ADDED SRM/517-U/1A.cpp Index: SRM/517-U/1A.cpp ================================================================== --- SRM/517-U/1A.cpp +++ SRM/517-U/1A.cpp @@ -0,0 +1,114 @@ +#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 CompositeSmash { public: + string thePossible(int N, int target) + { + return avoid(N, target) ? "No" : "Yes"; + } + + bool avoid(LL N, LL T) + { + if( N == T ) + return false; + if( N < T ) + return true; + bool composit = false; + for(LL d=2; d*d<=N && d +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(_, CompositeSmash().thePossible(N, target));} +int main(){ + +CASE(0) + int N = 517; + int target = 47; + string _ = "Yes"; +END +CASE(1) + int N = 8; + int target = 4; + string _ = "Yes"; +END +CASE(2) + int N = 12; + int target = 6; + string _ = "No"; +END +CASE(3) + int N = 5; + int target = 8; + string _ = "No"; +END +CASE(4) + int N = 100000; + int target = 100000; + string _ = "Yes"; +END +CASE(5) + int N = 5858; + int target = 2; + string _ = "Yes"; +END +CASE(6) + int N = 81461; + int target = 2809; + string _ = "No"; +END +CASE(7) + int N = 65536; + int target = 256; + string _ = "No"; +END +/* +CASE(8) + int N = 72; + int target = 4; + string _ = "Yes"; +END +CASE(9) + int N = ; + int target = ; + string _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/517-U/1B.cpp Index: SRM/517-U/1B.cpp ================================================================== --- SRM/517-U/1B.cpp +++ SRM/517-U/1B.cpp @@ -0,0 +1,145 @@ +#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 LL MODVAL = 1000000007; +class AdjacentSwaps { public: + int theCount(vector p) + { + int N = p.size(); + + vector< set > child(N-1); + for(int s=0; s s+1 --> ... --> e-1 <-- e + if(s-1>=0) child[s].insert(s-1); + for(int i=s; i+1<=e-1; ++i) child[i].insert(i+1); + if(e e ) { + // e-1 --> e <-- e+1 <-- ... <-- s-1 --> s + if(e-1>=0) child[e-1].insert(e); + for(int i=e; i+1<=s-1; ++i) child[i+1].insert(i); + if(s q(N-1); + for(int i=0; i+1, LL> memo; + LL rec(const vector& q, int i, int x, int y) + { + if( i == q.size() ) + return 1; + pair key(i,x); + if( memo.count(key) ) + return memo[key]; + + if( q[i] == -1 ) { + LL sum = 0; + for(int k=0; k +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(_, AdjacentSwaps().theCount(p));} +int main(){ + +CASE(0) + int p_[] = {1, 2, 0}; + vector p(p_, p_+sizeof(p_)/sizeof(*p_)); + int _ = 1; +END +CASE(1) + int p_[] = {0, 1}; + vector p(p_, p_+sizeof(p_)/sizeof(*p_)); + int _ = 0; +END +CASE(2) + int p_[] = {2, 0, 3, 1}; + vector p(p_, p_+sizeof(p_)/sizeof(*p_)); + int _ = 2; +END +CASE(3) + int p_[] = {1, 0, 3, 2}; + vector p(p_, p_+sizeof(p_)/sizeof(*p_)); + int _ = 0; +END +CASE(4) + int p_[] = {1, 3, 0, 5, 2, 7, 4, 8, 10, 6, 12, 9, 14, 11, 16, 13, 18, 15, 19, 17}; + vector p(p_, p_+sizeof(p_)/sizeof(*p_)); + int _ = 716743312; +END +/* +CASE(5) + int p_[] = ; + vector p(p_, p_+sizeof(p_)/sizeof(*p_)); + int _ = ; +END +CASE(6) + int p_[] = ; + vector p(p_, p_+sizeof(p_)/sizeof(*p_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/517-U/1C-U.cpp Index: SRM/517-U/1C-U.cpp ================================================================== --- SRM/517-U/1C-U.cpp +++ SRM/517-U/1C-U.cpp @@ -0,0 +1,146 @@ +#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 ColorfulBoard { public: + int theMin(vector board) + { + int H = board.size(); + int W = board[0].size(); + + vector okY(H), okX(W); + for(bool changed=true; changed; ) + { + changed = false; + for(int y=0; y cc(board[y].begin(), board[y].end()); + cc.erase('*'); + if( cc.size() == 1 ) { + okY[y] = changed = true; + for(int x=0; x cc; + for(int y=0; y +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(_, ColorfulBoard().theMin(board));} +int main(){ + +CASE(0) + string board_[] = {"SSS", + "SRR", + "SMM"}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int _ = 4; +END +CASE(1) + string board_[] = {"BBBBBBBB", + "BBBBBBBB", + "BBBBBBBB", + "BBBBBBBB", + "BBBBBBBB"}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int _ = 5; +END +CASE(2) + string board_[] = {"Ab", + "bA"}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int _ = -1; +END +CASE(3) + string board_[] = {"iiiii", + "iwiwi"} +; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int _ = 4; +END +CASE(4) + string board_[] = {"ffffffffff", + "xfxxoofoxo", + "ffffffffff", + "xfxxoofoxo", + "ffffffffff", + "ooxxoofoxo", + "xfxxoofoxo", + "xfxxoxfxxo", + "ffxxofffxo", + "xfxxoxfxxo"}; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int _ = 17; +END +/* +CASE(5) + string board_[] = ; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int _ = ; +END +CASE(6) + string board_[] = ; + vector board(board_, board_+sizeof(board_)/sizeof(*board_)); + int _ = ; +END +*/ +} +// END CUT HERE