ADDED SRM/561-U/1A.cpp Index: SRM/561-U/1A.cpp ================================================================== --- SRM/561-U/1A.cpp +++ SRM/561-U/1A.cpp @@ -0,0 +1,150 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef long double LD; +typedef complex CMP; + +class ICPCBalloons { public: + static const int INF = 0x3fffffff; + + int minRepaintings(vector balloonCount, string balloonSize, vector maxAccepted) + { + const int N = balloonCount.size(); + const int Q = maxAccepted.size(); + + vector M, L; + for(int i=0; i forM, forL; + for(int i=0; i& b, const vector q) + { + int more = 0; + int less = 0; + for(int i=0; i= q[i]) { + more += bi - q[i]; + } else { + less += q[i] - bi; + } + } + for(int i=q.size(); i=less ? less : INF); + } +}; + +// 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(_, ICPCBalloons().minRepaintings(balloonCount, balloonSize, maxAccepted));} +int main(){ + +CASE(0) + int balloonCount_[] = {100}; + vector balloonCount(balloonCount_, balloonCount_+sizeof(balloonCount_)/sizeof(*balloonCount_)); + string balloonSize = "L"; + int maxAccepted_[] = {1,2,3,4,5}; + vector maxAccepted(maxAccepted_, maxAccepted_+sizeof(maxAccepted_)/sizeof(*maxAccepted_)); + int _ = 10; +END +CASE(1) + int balloonCount_[] = {100}; + vector balloonCount(balloonCount_, balloonCount_+sizeof(balloonCount_)/sizeof(*balloonCount_)); + string balloonSize = "M"; + int maxAccepted_[] = {10,20,30,40,50}; + vector maxAccepted(maxAccepted_, maxAccepted_+sizeof(maxAccepted_)/sizeof(*maxAccepted_)); + int _ = -1; +END +CASE(2) + int balloonCount_[] = {5,6,1,5,6,1,5,6,1}; + vector balloonCount(balloonCount_, balloonCount_+sizeof(balloonCount_)/sizeof(*balloonCount_)); + string balloonSize = "MLMMLMMLM"; + int maxAccepted_[] = {7,7,4,4,7,7}; + vector maxAccepted(maxAccepted_, maxAccepted_+sizeof(maxAccepted_)/sizeof(*maxAccepted_)); + int _ = 6; +END +CASE(3) + int balloonCount_[] = {100,100}; + vector balloonCount(balloonCount_, balloonCount_+sizeof(balloonCount_)/sizeof(*balloonCount_)); + string balloonSize = "ML"; + int maxAccepted_[] = {50,51,51}; + vector maxAccepted(maxAccepted_, maxAccepted_+sizeof(maxAccepted_)/sizeof(*maxAccepted_)); + int _ = -1; +END +CASE(4) + int balloonCount_[] = {8,5,1,4,1,1,3,1,3,3,5,4,5,6,9}; + vector balloonCount(balloonCount_, balloonCount_+sizeof(balloonCount_)/sizeof(*balloonCount_)); + string balloonSize = "MMMLLLMMLLMLMLM"; + int maxAccepted_[] = {3,5,3,3,5,6,4,6,4,2,3,7,1,5,2}; + vector maxAccepted(maxAccepted_, maxAccepted_+sizeof(maxAccepted_)/sizeof(*maxAccepted_)); + int _ = 5; +END +CASE(5) + int balloonCount_[] = {1,18,4,7,19,7,7,1,4,8,10,5,14,13,8,22,6,3,13,5,3,4,2,1,3,15,19,4,5,9,4,11,2,7,12,20,11,26,22,7,2,10,9,20,13,20,2,9,11,9}; + vector balloonCount(balloonCount_, balloonCount_+sizeof(balloonCount_)/sizeof(*balloonCount_)); + string balloonSize = "LLMLLLLMLLLLLLLLLLLLMLLLLLLLLLLMMLMLLLMLLLLLLLLMLL"; + int maxAccepted_[] = {44,59,29,53,16,23,13,14,29,42,13,15,66,4,47}; + vector maxAccepted(maxAccepted_, maxAccepted_+sizeof(maxAccepted_)/sizeof(*maxAccepted_)); + int _ = 210; +END +/* +CASE(6) + int balloonCount_[] = ; + vector balloonCount(balloonCount_, balloonCount_+sizeof(balloonCount_)/sizeof(*balloonCount_)); + string balloonSize = ; + int maxAccepted_[] = ; + vector maxAccepted(maxAccepted_, maxAccepted_+sizeof(maxAccepted_)/sizeof(*maxAccepted_)); + int _ = ; +END +CASE(7) + int balloonCount_[] = ; + vector balloonCount(balloonCount_, balloonCount_+sizeof(balloonCount_)/sizeof(*balloonCount_)); + string balloonSize = ; + int maxAccepted_[] = ; + vector maxAccepted(maxAccepted_, maxAccepted_+sizeof(maxAccepted_)/sizeof(*maxAccepted_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/561-U/1B-U.cpp Index: SRM/561-U/1B-U.cpp ================================================================== --- SRM/561-U/1B-U.cpp +++ SRM/561-U/1B-U.cpp @@ -0,0 +1,201 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef long double LD; +typedef complex CMP; + +class CirclesGame { public: + string whoCanWin(vector x, vector y, vector r) + { + vector< pair > > xyr; + const int N = x.size(); + for(int i=0; i parent(N, -1); + for(int i=0; i& p) + { + vector r; + vector< vector > c(N); + for(int i=0; i memo; + int grundy(const vector< vector >& ch, int v) + { + if(memo[v]!=-1) + return memo[v]; + + vector next; + rec(ch, v, 0, next); + return memo[v] = mex(next); + } + + void rec(const vector< vector >& ch, int v, int XOR_acc, vector& next) + { + int XOR = XOR_acc; + for(int i=0; i& next) + { + sort(next.begin(), next.end()); + 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 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(_, CirclesGame().whoCanWin(x, y, r));} +int main(){ + +CASE(0) + int x_[] = {0}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {0}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = {1}; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + string _ = "Alice"; +END +CASE(1) + int x_[] = {0, 3}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {0, 0}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = {1, 1}; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + string _ = "Bob"; +END +CASE(2) + int x_[] = {0, 0, 5}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {0, 0, 0}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = {1, 2, 1}; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + string _ = "Alice"; +END +CASE(3) + int x_[] = {0, 0, 0, 10, 10, 20}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {0, 0, 0, 0, 0, 0}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = {1, 2, 3, 1, 2, 1}; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + string _ = "Bob"; +END +CASE(4) + int x_[] = {10,20,30,40,50,60,70,80}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {8,7,6,5,4,3,2,1}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = {2,2,2,2,2,2,2,2}; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + string _ = "Bob"; +END +CASE(5) + int x_[] = {0, 3, 6, 9, 12, -4747, -4777}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {-5858, -5858, -5858, -5858, -5858, 777, 777}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = {58, 1, 1, 1, 1, 44, 8}; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + string _ = "Bob"; +END +CASE(6) + int x_[] = {5202, 5699, -7433, 5068, -9483, -684, -6593, 5108, -7813, 6823, 3267, -8222, -8547, 2878, 2413, 8557, 5149, 5073, -8638, -6108, 8097}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = {8728, -7407, 4338, -8414, 7652, -3705, -984, 5976, -9180, -9119, 9301, 2398, 7915, 6205, 7665, 717, -9884, 11, -8579, -6903, -746}; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = {4196, 9303, 7152, 5875, 2943, 788, 502, 416, 1958, 3174, 182, 1256, 1147, 444, 979, 65, 1040, 1233, 438, 175, 1140}; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + string _ = "Alice"; +END +/* +CASE(7) + int x_[] = ; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = ; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = ; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + string _ = ; +END +CASE(8) + int x_[] = ; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int y_[] = ; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int r_[] = ; + vector r(r_, r_+sizeof(r_)/sizeof(*r_)); + string _ = ; +END +*/ +} +// END CUT HERE