ADDED SRM/502-U/1A.cpp Index: SRM/502-U/1A.cpp ================================================================== --- SRM/502-U/1A.cpp +++ SRM/502-U/1A.cpp @@ -0,0 +1,101 @@ +#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 TheLotteryBothDivs { public: + double find(vector goodSuffixes) + { + sort(goodSuffixes.begin(), goodSuffixes.end()); + goodSuffixes.erase(unique(goodSuffixes.begin(), goodSuffixes.end()), goodSuffixes.end()); + double p = 0.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 double& Expected, const double& Received) { + bool ok = (abs(Expected - Received) < 1e-9); + 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(_, TheLotteryBothDivs().find(goodSuffixes));} +int main(){ + +CASE(0) + string goodSuffixes_[] = {"4"}; + vector goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); + double _ = 0.1; +END +CASE(1) + string goodSuffixes_[] = {"4", "7"}; + vector goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); + double _ = 0.2; +END +CASE(2) + string goodSuffixes_[] = {"47", "47"}; + vector goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); + double _ = 0.01; +END +CASE(3) + string goodSuffixes_[] = {"47", "58", "4747", "502"}; + vector goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); + double _ = 0.021; +END +CASE(4) + string goodSuffixes_[] = {"8542861", "1954", "6", "523", "000000000", "5426", "8"}; + vector goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); + double _ = 0.201100101; +END +/* +CASE(5) + string goodSuffixes_[] = ; + vector goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); + double _ = ; +END +CASE(6) + string goodSuffixes_[] = ; + vector goodSuffixes(goodSuffixes_, goodSuffixes_+sizeof(goodSuffixes_)/sizeof(*goodSuffixes_)); + double _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/502-U/1B-U.cpp Index: SRM/502-U/1B-U.cpp ================================================================== --- SRM/502-U/1B-U.cpp +++ SRM/502-U/1B-U.cpp @@ -0,0 +1,161 @@ +#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 TheProgrammingContestDivOne { public: + struct Problem + { + LL M; + LL D; + LL R; + bool operator<(const Problem& rhs) const { + if(R != rhs.R) return R < rhs.R; + if(D != rhs.D) return D > rhs.D; + return M > rhs.M; + } + }; + int find(int T, vector maxPoints, vector pointsPerMinute, vector requiredTime) + { + const int N = maxPoints.size(); + vector ps; + for(int i=0; i st; + st[0] = 0; + for(int i=0; i st2 = st; + for(map::iterator it=st.begin(); it!=st.end(); ++it) + { + LL s = it->first; + LL t = it->second; + LL t2 = t + ps[i].R; + if( t2 <= T ) { + LL s2 = s + ps[i].M - ps[i].D * t2; + best = max(best, s2); + if( s2 > s ) { + LL& entry = st2[s2]; + if( entry==0 || entry>t2 ) + entry = t2; + } + } + } + st.swap(st2); + } + return int(best); + } +}; + +// 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(_, TheProgrammingContestDivOne().find(T, maxPoints, pointsPerMinute, requiredTime));} +int main(){ + +CASE(0) + int T = 74; + int maxPoints_[] = {502}; + vector maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); + int pointsPerMinute_[] = {2}; + vector pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); + int requiredTime_[] = {47}; + vector requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); + int _ = 408; +END +CASE(1) + int T = 40000; + int maxPoints_[] = {100000, 100000}; + vector maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); + int pointsPerMinute_[] = {1, 100000}; + vector pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); + int requiredTime_[] = {50000, 30000}; + vector requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); + int _ = 0; +END +CASE(2) + int T = 75; + int maxPoints_[] = {250, 500, 1000}; + vector maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); + int pointsPerMinute_[] = {2, 4, 8}; + vector pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); + int requiredTime_[] = {25, 25, 25}; + vector requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); + int _ = 1200; +END +CASE(3) + int T = 30; + int maxPoints_[] = {100, 100, 100000}; + vector maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); + int pointsPerMinute_[] = {1, 1, 100}; + vector pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); + int requiredTime_[] = {15, 15, 30}; + vector requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); + int _ = 97000; +END +CASE(4) + int T = 100000; + int maxPoints_[] = {100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,}; + vector maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); + int pointsPerMinute_[] = {10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,}; + vector pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); + int requiredTime_[] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,4,4}; + vector requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); + int _ = -1; +END +CASE(5) + int T = 100000; + int maxPoints_[] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,100000,}; + vector maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); + int pointsPerMinute_[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; + vector pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); + int requiredTime_[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; + vector requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); + int _ = -1; +END +/* +CASE(5) + int T = ; + int maxPoints_[] = ; + vector maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); + int pointsPerMinute_[] = ; + vector pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); + int requiredTime_[] = ; + vector requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); + int _ = ; +END +*/ +} +// END CUT HERE