ADDED SRM/522-U/1A.cpp Index: SRM/522-U/1A.cpp ================================================================== --- SRM/522-U/1A.cpp +++ SRM/522-U/1A.cpp @@ -0,0 +1,115 @@ +#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 RowAndCoins { public: + string getWinner(string cells) + { + int n = cells.size(); + int v = 0; + for(int i=0; i memo; + int rec(int p, const int v, const int n, int mask) + { + int key = mask*2+p; + if( key >= memo.size() ) + memo.resize(key+1, -1); + if( memo[key] >= 0 ) + return memo[key]; + + 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(_, RowAndCoins().getWinner(cells));} +int main(){ + +CASE(0) + string cells = "ABBB"; + string _ = "Alice"; +END +CASE(1) + string cells = "BBBB"; + string _ = "Bob"; +END +CASE(2) + string cells = "BA"; + string _ = "Alice"; +END +CASE(3) + string cells = "BABBABBB"; + string _ = "Bob"; +END +CASE(4) + string cells = "ABABBBABAABBAA"; + string _ = "Alice"; +END +CASE(5) + string cells = "BBBAAABBAAABBB"; + string _ = "Bob"; +END +CASE(6) + string cells = "A"; + string _ = "Alice"; +END +CASE(7) + string cells = "B"; + string _ = "Bob"; +END + +} +// END CUT HERE ADDED SRM/522-U/1B.cpp Index: SRM/522-U/1B.cpp ================================================================== --- SRM/522-U/1B.cpp +++ SRM/522-U/1B.cpp @@ -0,0 +1,121 @@ +#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 CorrectMultiplication { public: + long long getMinimum(int a, int b, int c) + { + return solve(a,b,c); + } + + LL solve(LL a, LL b, LL c) + { + if( a > b ) + swap(a,b); + LL vv = (1LL<<62); + for(LL A=1; A*A <= (a+b+c)*2; ++A) + vv = min(vv, best_of(A,a,b,c)); + return vv; + } + + LL best_of(LL A, LL a, LL b, LL c) + { + LL Bl = 1; + LL Br = a+b+c; + while( Bl+3 < Br ) + { + LL Bc1 = (Bl*2+Br*1) / 3; + LL Bc2 = (Bl*1+Br*2) / 3; + LL cc1 = abs(A-a)+abs(Bc1-b)+abs(A*Bc1-c); + LL cc2 = abs(A-a)+abs(Bc2-b)+abs(A*Bc2-c); + if(cc1 < cc2) + Br = Bc2; + else + Bl = Bc1; + } + LL vv = (1LL<<62); + for(LL B=Bl; B<=Br; ++B) + vv = min(vv, abs(A-a)+abs(B-b)+abs(A*B-c)); + return vv; + } +}; + +// 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 long long& Expected, const long long& 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(_, CorrectMultiplication().getMinimum(a, b, c));} +int main(){ + +CASE(0) + int a = 19; + int b = 28; + int c = 522; + long long _ = 2LL; +END +CASE(1) + int a = 10; + int b = 30; + int c = 500; + long long _ = 11LL; +END +CASE(2) + int a = 11111; + int b = 11111; + int c = 123454321; + long long _ = 0LL; +END +CASE(3) + int a = 1000; + int b = 100; + int c = 10; + long long _ = 1089LL; +END +CASE(4) + int a = 399; + int b = 522; + int c = 199999; + long long _ = 24LL; +END +CASE(5) + int a = 1000000000; + int b = 1000000000; + int c = 1000000000; + long long _ = -1LL; +END +/* +CASE(6) + int a = ; + int b = ; + int c = ; + long long _ = LL; +END +*/ +} +// END CUT HERE ADDED SRM/522-U/1C-U.cpp Index: SRM/522-U/1C-U.cpp ================================================================== --- SRM/522-U/1C-U.cpp +++ SRM/522-U/1C-U.cpp @@ -0,0 +1,126 @@ +#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 PointErasing { public: + vector ans; + + vector getOutcomes(vector y) + { + rec(1, y, y[0], y[1], 1); + return ans; + } + + void rec(int i, const vector& y, int lo, int hi, int c) + { + if( i == y.size() ) { + if(c>1) + ans.push_back(c); + return; + } + rec(i+1, y, lo, hi, c); + + if( lo < y[i] && y[i] < hi ) { + ans.push_back(c+1); + return; + } + + } +}; + +// 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 vector & Expected, const vector & 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(_, PointErasing().getOutcomes(y));} +int main(){ + +CASE(0) + int y_[] = { 1, 2, 1, 1, 0, 4, 3 }; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = {4, 6 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(1) + int y_[] = { 0, 0, 4, 4, 8, 8, 4, 4 }; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = {6 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(2) + int y_[] = { 522 }; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = {1 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(3) + int y_[] = { 19, 19, 19, 19, 19, 19 }; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = {6 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(4) + int y_[] = { 0, 1, 2, 3, 4 }; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = {2 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(5) + int y_[] = { 7, 8, 8, 7, 6, 7, 9, 3, 5, 0 }; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = {3, 4, 5 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(6) + int y_[] = { 3, 2, 3, 3, 4, 3, 4, 3, 3, 1, 5, 3 }; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = {4, 5, 6, 7, 9 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(7) + int y_[] = { 5, 5, 4, 4, 5, 8, 5, 5, 5, 5, 5, 9, 2, 0, 9, 4, 5, 5, 3, 4, 4, 4, 4, 7, 4 }; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = {6, 7, 8, 10, 11, 12, 13, 15, 16, 17 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(8) + int y_[] = ; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = ; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(9) + int y_[] = ; + vector y(y_, y_+sizeof(y_)/sizeof(*y_)); + int __[] = ; + vector _(__, __+sizeof(__)/sizeof(*__)); +END + +} +// END CUT HERE