ADDED SRM/528/1A.cpp Index: SRM/528/1A.cpp ================================================================== --- SRM/528/1A.cpp +++ SRM/528/1A.cpp @@ -0,0 +1,107 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __GNUC__ +#include +#define unordered_map __gnu_cxx::hash_map +#else +#include +#endif +using namespace std; +typedef long long LL; +typedef complex CMP; + +class Cut { public: + static bool TensFirst(int a, int b) + { + if(a%10 != b%10) + return a%10 < b%10; + return a < b; + } + + int getMaximum(vector eelLengths, int maxCuts) + { + sort(eelLengths.begin(), eelLengths.end(), &TensFirst); + + int una = 0; + for(int i=0; i10 ) + una++, maxCuts--, e-=10; + if( e == 10 ) + una++; + } + return una; + } +}; + +// 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(_, Cut().getMaximum(eelLengths, maxCuts));} +int main(){ + +CASE(0) + int eelLengths_[] = {13, 20, 13}; + vector eelLengths(eelLengths_, eelLengths_+sizeof(eelLengths_)/sizeof(*eelLengths_)); + int maxCuts = 2; + int _ = 3; +END +CASE(1) + int eelLengths_[] = {5, 5, 5, 5}; + vector eelLengths(eelLengths_, eelLengths_+sizeof(eelLengths_)/sizeof(*eelLengths_)); + int maxCuts = 2; + int _ = 0; +END +CASE(2) + int eelLengths_[] = {34, 10, 48}; + vector eelLengths(eelLengths_, eelLengths_+sizeof(eelLengths_)/sizeof(*eelLengths_)); + int maxCuts = 4; + int _ = 5; +END +CASE(3) + int eelLengths_[] = {30, 50, 30, 50}; + vector eelLengths(eelLengths_, eelLengths_+sizeof(eelLengths_)/sizeof(*eelLengths_)); + int maxCuts = 350; + int _ = 16; +END +/* +CASE(4) + int eelLengths_[] = ; + vector eelLengths(eelLengths_, eelLengths_+sizeof(eelLengths_)/sizeof(*eelLengths_)); + int maxCuts = ; + int _ = ; +END +CASE(5) + int eelLengths_[] = ; + vector eelLengths(eelLengths_, eelLengths_+sizeof(eelLengths_)/sizeof(*eelLengths_)); + int maxCuts = ; + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/528/1B.cpp Index: SRM/528/1B.cpp ================================================================== --- SRM/528/1B.cpp +++ SRM/528/1B.cpp @@ -0,0 +1,127 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __GNUC__ +#include +#define unordered_map __gnu_cxx::hash_map +#else +#include +#endif +using namespace std; +typedef long long LL; +typedef complex CMP; + +template +struct DP2x +{ + const int N1, N2; + vector data; + DP2x(int, int N2, const T& t = T()) + : N1(2), N2(N2), data(N1*N2, t) { assert(data.size()*sizeof(T)<(1<<26)); } + T& operator()(int i1, int i2) + { i1&=1; return data[ (i1*N2)+i2 ]; } + void swap(DP2x& rhs) + { data.swap(rhs.data); } +}; + +class SPartition { public: + long long getCount(string s) + { + if( s.size()%2 != 0 ) + return 0; + + int N = s.size()/2; + DP2x dp(s.size()+1, 1<=0; --i) + for(int bits=0,ni=min(N,i); bits<(1< +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(_, SPartition().getCount(s));} +int main(){ + +CASE(0) + string s = "oxox"; + long long _ = 2LL; +END +CASE(1) + string s = "oooxxx"; + long long _ = 0LL; +END +CASE(2) + string s = "xoxxox"; + long long _ = 4LL; +END +CASE(3) + string s = "xo"; + long long _ = 0LL; +END +CASE(4) + string s = "ooooxoox"; + long long _ = 8LL; +END +CASE(5) + string s = "ooxxoxox"; + long long _ = 8LL; +END +CASE(6) + string s = "oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox"; + long long _ = -1LL; +END +/* +CASE(7) + string s = ; + long long _ = LL; +END +*/ +} +// END CUT HERE ADDED SRM/528/1C.cpp Index: SRM/528/1C.cpp ================================================================== --- SRM/528/1C.cpp +++ SRM/528/1C.cpp @@ -0,0 +1,132 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __GNUC__ +#include +#define unordered_map __gnu_cxx::hash_map +#else +#include +#endif +using namespace std; +typedef long long LL; +typedef complex CMP; + +template +struct DP2x +{ + const int N1, N2; + vector data; + DP2x(int, int N2, const T& t = T()) + : N1(2), N2(N2), data(N1*N2, t) { assert(data.size()*sizeof(T)<(1<<26)); } + T& operator()(int i1, int i2) + { i1&=1; return data[ (i1*N2)+i2 ]; } + void swap(DP2x& rhs) + { data.swap(rhs.data); } +}; + +class ColorfulCookie { public: + int getMaximum(vector cookies, int P1, int P2) + { + int L = 0; + int R = accumulate(cookies.begin(), cookies.end(), 0) / (P1+P2) + 1; + while( R-L > 1 ) { // [L, R) + int C = (L+R) / 2; + (possible(cookies, P1, P2, C) ? L : R) = C; + } + return L * (P1+P2); + } + + bool possible(const vector& C, int P1, int P2, int Times) + { + DP2x maxP2forP1(C.size()+1, Times+1, -1); + maxP2forP1(0,0) = 0; + for(int i=0; i=0 && maxP2forP1(i,n-a)>=0 && C[i]-a*P1>=0 ) + maxP2forP1(i+1,n) = max(maxP2forP1(i+1,n), + maxP2forP1(i,n-a) + min(Times-a,(C[i]-a*P1)/P2) + ); + } + } + return maxP2forP1(C.size(), Times) >= Times; + } +}; + +// 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(_, ColorfulCookie().getMaximum(cookies, P1, P2));} +int main(){ + +CASE(0) + int cookies_[] = {100, 100}; + vector cookies(cookies_, cookies_+sizeof(cookies_)/sizeof(*cookies_)); + int P1 = 50; + int P2 = 50; + int _ = 200; +END +CASE(1) + int cookies_[] = {50, 250, 50}; + vector cookies(cookies_, cookies_+sizeof(cookies_)/sizeof(*cookies_)); + int P1 = 50; + int P2 = 100; + int _ = 300; +END +CASE(2) + int cookies_[] = {2000}; + vector cookies(cookies_, cookies_+sizeof(cookies_)/sizeof(*cookies_)); + int P1 = 100; + int P2 = 200; + int _ = 0; +END +CASE(3) + int cookies_[] = {123, 456, 789, 555}; + vector cookies(cookies_, cookies_+sizeof(cookies_)/sizeof(*cookies_)); + int P1 = 58; + int P2 = 158; + int _ = 1728; +END +/* +CASE(4) + int cookies_[] = ; + vector cookies(cookies_, cookies_+sizeof(cookies_)/sizeof(*cookies_)); + int P1 = ; + int P2 = ; + int _ = ; +END +CASE(5) + int cookies_[] = ; + vector cookies(cookies_, cookies_+sizeof(cookies_)/sizeof(*cookies_)); + int P1 = ; + int P2 = ; + int _ = ; +END +*/ +} +// END CUT HERE Index: lib/typical/dp.cpp ================================================================== --- lib/typical/dp.cpp +++ lib/typical/dp.cpp @@ -10,11 +10,11 @@ { return data[ (i1*N2)+i2 ]; } void swap(DP2& rhs) { data.swap(rhs.data); } }; -// Tested: Codeforces #13 C +// Tested: Codeforces #13 C, SRM 528 Lv2 template struct DP2x { const int N1, N2; vector data;