ADDED SRM/649-U/1A.cpp Index: SRM/649-U/1A.cpp ================================================================== --- SRM/649-U/1A.cpp +++ SRM/649-U/1A.cpp @@ -0,0 +1,106 @@ +#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 Decipherability { public: + string check(string s, int K) + { + return has_unique_ans(s, s.size()-K) ? "Certain" : "Uncertain"; + } + + bool has_unique_ans(const string& s, int R) + { + if(R == 0) + return true; + + for(int a=0; a= R) + return false; + } + return true; + } +}; + +// 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 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(_, Decipherability().check(s, K));} +int main(){ + +CASE(0) + string s = "snuke"; + int K = 2; + string _ = "Certain"; +END +CASE(1) + string s = "aba"; + int K = 1; + string _ = "Certain"; +END +CASE(2) + string s = "aba"; + int K = 2; + string _ = "Uncertain"; +END +CASE(3) + string s = "abcdabcd"; + int K = 3; + string _ = "Certain"; +END +CASE(4) + string s = "koukyoukoukokukikou"; + int K = 2; + string _ = "Uncertain"; +END +CASE(5) + string s = "wolfsothe"; + int K = 8; + string _ = "Uncertain"; +END +CASE(6) + string s = "aa"; + int K = 2; + string _ = "Certain"; +END +/* +CASE(7) + string s = ; + int K = ; + string _ = ; +END +CASE(8) + string s = ; + int K = ; + string _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/649-U/1B.cpp Index: SRM/649-U/1B.cpp ================================================================== --- SRM/649-U/1B.cpp +++ SRM/649-U/1B.cpp @@ -0,0 +1,172 @@ +#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 XorSequence { public: + long long getmax(int N, int sz, int A0, int A1, int P, int Q, int R) + { + vector A(sz); + A[0] = A0; + A[1] = A1; + for(int i=2; i& A) + { + LL total = 0; + + vector> Sec(1, A); + for(int Bit=LN-1; Bit>=0; --Bit) { + vector> Next_Sec; + + LL p01=0, p10=0; + for(vector& A: Sec) { + vector A0, A1; + LL n0=0, n1=0; + 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 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(_, XorSequence().getmax(N, sz, A0, A1, P, Q, R));} +int main(){ + +CASE(0) + int N = 4; + int sz = 6; + int A0 = 3; + int A1 = 2; + int P = 0; + int Q = 1; + int R = 3; + long long _ = 8LL; +END +CASE(1) + int N = 8; + int sz = 8; + int A0 = 2; + int A1 = 5; + int P = 3; + int Q = 1; + int R = 4; + long long _ = 13LL; +END +CASE(2) + int N = 8; + int sz = 7; + int A0 = 3; + int A1 = 0; + int P = 1; + int Q = 2; + int R = 4; + long long _ = 12LL; +END +CASE(3) + int N = 32; + int sz = 15; + int A0 = 7; + int A1 = 9; + int P = 11; + int Q = 2; + int R = 1; + long long _ = 60LL; +END +CASE(4) + int N = 131072; + int sz = 131072; + int A0 = 7; + int A1 = 7; + int P = 1; + int Q = 0; + int R = 0; + long long _ = 0LL; +END +CASE(5) + int N = 131072; + int sz = 131070; + int A0 = 411; + int A1 = 415; + int P = 398; + int Q = 463; + int R = 9191; + long long _ = 4302679760LL; +END +/* +CASE(6) + int N = ; + int sz = ; + int A0 = ; + int A1 = ; + int P = ; + int Q = ; + int R = ; + long long _ = LL; +END +CASE(7) + int N = ; + int sz = ; + int A0 = ; + int A1 = ; + int P = ; + int Q = ; + int R = ; + long long _ = LL; +END +*/ +} +// END CUT HERE ADDED SRM/649-U/1C-U.cpp Index: SRM/649-U/1C-U.cpp ================================================================== --- SRM/649-U/1C-U.cpp +++ SRM/649-U/1C-U.cpp @@ -0,0 +1,149 @@ +#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 CartInSupermarket { public: + int calcmin(vector a, int b) + { + int L=0, R=*max_element(a.begin(), a.end()); // can do in (L,R] minutes + while(R-L>1) { + int C = (L+R)/2; + (can(a,b,C) ? R : L) = C; + } + return R; + } + + bool can(vector a, int b, int C) { + int sp = 0; + for(auto ai: a) { + int spx; + if(!need_split(ai, C, &spx)) + return false; + sp += spx; + } + return sp <= b; + } + + // Can we process A in C minutes? If so, return minimal necessary split to *spx. + bool need_split(int A, int C, int* spx) { + LL preM = 0; + for(int b=max(0,A/C-1) ;; ++b) { + LL M = cover(C, b); + if(M <= preM) + return false; + preM = M; + if(A<=M) { + *spx = b; + return true; + } + } + } + + // C minutes, b splits. How many we can cover. + LL cover(int C, int b) { + vector> stock(1, make_pair(C,1)); + while(b) { + if(b>=stock[0].second) { + b -= stock[0].second; + stock[0] = make_pair(stock[0].first-1, stock[0].second*2); + } else { + stock[0].second -= b; + stock.emplace_back(stock[0].first-1, b*2); + break; + } + } + + LL ans = 0; + for(auto cn: stock) { + if(cn.first<=0) + return -1; + ans += LL(cn.first)*cn.second; + } + return ans; + } +}; + +// 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(_, CartInSupermarket().calcmin(a, b));} +int main(){ + +CASE(0) + int a_[] = {8}; + vector a(a_, a_+sizeof(a_)/sizeof(*a_)); + int b = 3; + int _ = 4; +END +CASE(1) + int a_[] = {6,6,5}; + vector a(a_, a_+sizeof(a_)/sizeof(*a_)); + int b = 3; + int _ = 4; +END +CASE(2) + int a_[] = {12,5,6,2,6,8}; + vector a(a_, a_+sizeof(a_)/sizeof(*a_)); + int b = 4; + int _ = 6; +END +CASE(3) + int a_[] = {15,20,11,13,18,24,25,21,22,10,15,14,19}; + vector a(a_, a_+sizeof(a_)/sizeof(*a_)); + int b = 0; + int _ = 25; +END +CASE(4) + int a_[] = {671122748,846444748,84701624,608579554,672060899,967957440,31438849,734849843,376589643,904285209 +,80693344,211737743,85405464,444633541,293184188,935462519,146753109,972886045,496631016,601669536 +,257574086,958464570,6294570,546189534,668105964,601197313,784337929,921840143,70408284,722040626 +,253400894,56411549,811940644,152086353,122638884,776352066,118932182,177589709,538122558,127914469 +,523761221,290027568,734517444,819458123,699130727,784698122,810265337,283326309,593596316,368671876}; + vector a(a_, a_+sizeof(a_)/sizeof(*a_)); + int b = 6478; + int _ = 3805054; +END +CASE(5) + int a_[] = {977827843, 601538780, 476956916, 821358251, 646377015, 479421294, 631863623, 446866211, 147800371, 777376159, 997915782, 317155640, 611683333, 461303085, 473215018, 363166652, 39746841, 109934430, 391345044, 41220128, 379970887, 445787345, 801764390, 886145854, 494435459, 974163022, 126739284, 708338618, 775199509, 378383243, 928615727, 606884963}; + vector a(a_, a_+sizeof(a_)/sizeof(*a_)); + int b = 278304610; + int _ = -1; +END + +/* +CASE(6) + int a_[] = ; + vector a(a_, a_+sizeof(a_)/sizeof(*a_)); + int b = ; + int _ = ; +END +*/ +} +// END CUT HERE