ADDED SRM/514-U/1A.cpp Index: SRM/514-U/1A.cpp ================================================================== --- SRM/514-U/1A.cpp +++ SRM/514-U/1A.cpp @@ -0,0 +1,97 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +class MagicalGirlLevelOneDivOne { public: + string isReachable(vector jumpTypes, int x, int y) + { + bool hasEven = false; + for(int i=0; i +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const string& Expected, const string& Received) { + bool ok = (Expected == Received); + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); +#define END verify_case(_, MagicalGirlLevelOneDivOne().isReachable(jumpTypes, x, y));} +int main(){ + +CASE(0) + int jumpTypes_[] = {2}; + vector jumpTypes(jumpTypes_, jumpTypes_+sizeof(jumpTypes_)/sizeof(*jumpTypes_)); + int x = 5; + int y = 4; + string _ = "YES"; +END +CASE(1) + int jumpTypes_[] = {3}; + vector jumpTypes(jumpTypes_, jumpTypes_+sizeof(jumpTypes_)/sizeof(*jumpTypes_)); + int x = 5; + int y = 4; + string _ = "NO"; +END +CASE(2) + int jumpTypes_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + vector jumpTypes(jumpTypes_, jumpTypes_+sizeof(jumpTypes_)/sizeof(*jumpTypes_)); + int x = 1000000000; + int y = -999999999; + string _ = "YES"; +END +CASE(3) + int jumpTypes_[] = {999999999}; + vector jumpTypes(jumpTypes_, jumpTypes_+sizeof(jumpTypes_)/sizeof(*jumpTypes_)); + int x = 999999999; + int y = 0; + string _ = "NO"; +END +/* +CASE(4) + int jumpTypes_[] = ; + vector jumpTypes(jumpTypes_, jumpTypes_+sizeof(jumpTypes_)/sizeof(*jumpTypes_)); + int x = ; + int y = ; + string _ = ; +END +CASE(5) + int jumpTypes_[] = ; + vector jumpTypes(jumpTypes_, jumpTypes_+sizeof(jumpTypes_)/sizeof(*jumpTypes_)); + int x = ; + int y = ; + string _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/514-U/2A-U.cpp Index: SRM/514-U/2A-U.cpp ================================================================== --- SRM/514-U/2A-U.cpp +++ SRM/514-U/2A-U.cpp @@ -0,0 +1,260 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +static const int MODVAL = 1000000007; + +struct UnionFind +{ + vector uf, sz; + int nc; + + UnionFind(int N): uf(N), sz(N,1), nc(N) + { for(int i=0; i= sz[b] ) swap(a, b); + uf[a] = b; + sz[b] += sz[a]; + --nc; + } + return (a!=b); + } +}; + +struct mint +{ + int val; + mint():val(0){} + mint(int x):val(x%MODVAL) {} + mint(LL x):val(x%MODVAL) {} +}; +mint operator+(mint x, mint y) { return x.val+y.val; } +mint operator-(mint x, mint y) { return x.val-y.val+MODVAL; } +mint operator*(mint x, mint y) { return LL(x.val)*y.val; } +mint POW(mint x, int e) { + mint v = 1; + for(;e;x=x*x,e>>=1) + if(e&1) + v=v*x; + return v; +} + +class MagicalGirlLevelTwoDivOne { public: + int theCount(vector palette, int n, int m) + { + if( (n^m)&1 ) + return 0; + int H = palette.size(); + int W = palette[0].size(); + + #define key(y,x) (2+(y)*W+(x)) + + UnionFind uf(W*H+2); + for(int y=0; y=0 ) + uf.Union(key(y,x), key(y-n,x)); + if( x-m>=0 ) + uf.Union(key(y,x), key(y,x-m)); + } + + if( uf.Find(0) == uf.Find(1) ) + return 0; + + vector< vector > dep(n, vector(m)); + vector< vector > stt(n, vector(m)); + for(int y=0; y memo; + int rec(const vector< vector >& dep, const vector< vector >& stt, const int H, const int W, + int y, int status) + { + if( y == H ) + if( status == (1<>x)&1 ) + ++odd; + int odddep = 0; + int evendep = 0; + if(odd%2 == 0) + goto next; + for(int x=0; x>x)&1) ) + goto next; + for(int x=0; x>x)&1) ? odddep : evendep) += d; + } + cur = cur * POW(5, odddep); + cur = cur * POW(4,evendep); + cur = cur * rec(dep, stt, H, W, y+1, status^bits); + total = total + cur; + next:; + } + return memo[me] = total.val; + } +}; + +// BEGIN CUT HERE +#include +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const int& Expected, const int& Received) { + bool ok = (Expected == Received); + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); +#define END verify_case(_, MagicalGirlLevelTwoDivOne().theCount(palette, n, m));} +int main(){ + +CASE(0) + string palette_[] = {"12", + "2."}; + vector palette(palette_, palette_+sizeof(palette_)/sizeof(*palette_)); + int n = 2; + int m = 2; + int _ = 5; +END +CASE(1) + string palette_[] = {"21", + "1."}; + vector palette(palette_, palette_+sizeof(palette_)/sizeof(*palette_)); + int n = 2; + int m = 2; + int _ = 4; +END +CASE(2) + string palette_[] = {"...", + "...", + "..."}; + vector palette(palette_, palette_+sizeof(palette_)/sizeof(*palette_)); + int n = 1; + int m = 1; + int _ = 1953125; +END +CASE(3) + string palette_[] = {"..58..", + "..47.."}; + vector palette(palette_, palette_+sizeof(palette_)/sizeof(*palette_)); + int n = 2; + int m = 3; + int _ = 0; +END +CASE(4) + string palette_[] = {"...1.2.3", + "4.5.6...", + "...7.8.9", + "1.2.3..."}; + vector palette(palette_, palette_+sizeof(palette_)/sizeof(*palette_)); + int n = 4; + int m = 4; + int _ = 886073030; +END +CASE(5) + string palette_[] = {"....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "....................", + "...................."}; + vector palette(palette_, palette_+sizeof(palette_)/sizeof(*palette_)); + int n = 10; + int m = 10; + int _ = 240076532; +END +/* +CASE(6) + string palette_[] = ; + vector palette(palette_, palette_+sizeof(palette_)/sizeof(*palette_)); + int n = ; + int m = ; + int _ = ; +END +CASE(7) + string palette_[] = ; + vector palette(palette_, palette_+sizeof(palette_)/sizeof(*palette_)); + int n = ; + int m = ; + int _ = ; +END +*/ +} +// END CUT HERE