4bef2b4eaf 2011-04-10 kinaba: #include <iostream> 4bef2b4eaf 2011-04-10 kinaba: #include <sstream> 4bef2b4eaf 2011-04-10 kinaba: #include <iomanip> 4bef2b4eaf 2011-04-10 kinaba: #include <vector> 4bef2b4eaf 2011-04-10 kinaba: #include <string> 4bef2b4eaf 2011-04-10 kinaba: #include <map> 4bef2b4eaf 2011-04-10 kinaba: #include <set> 4bef2b4eaf 2011-04-10 kinaba: #include <algorithm> 4bef2b4eaf 2011-04-10 kinaba: #include <numeric> 4bef2b4eaf 2011-04-10 kinaba: #include <iterator> 4bef2b4eaf 2011-04-10 kinaba: #include <functional> 4bef2b4eaf 2011-04-10 kinaba: #include <complex> 4bef2b4eaf 2011-04-10 kinaba: #include <queue> 4bef2b4eaf 2011-04-10 kinaba: #include <stack> 4bef2b4eaf 2011-04-10 kinaba: #include <cmath> 4bef2b4eaf 2011-04-10 kinaba: #include <cassert> 4bef2b4eaf 2011-04-10 kinaba: #include <cstring> 4bef2b4eaf 2011-04-10 kinaba: using namespace std; 4bef2b4eaf 2011-04-10 kinaba: typedef long long LL; 4bef2b4eaf 2011-04-10 kinaba: typedef complex<double> CMP; 4bef2b4eaf 2011-04-10 kinaba: 4bef2b4eaf 2011-04-10 kinaba: class TheProgrammingContestDivOne { public: 4bef2b4eaf 2011-04-10 kinaba: struct Problem 4bef2b4eaf 2011-04-10 kinaba: { 4bef2b4eaf 2011-04-10 kinaba: LL M; 4bef2b4eaf 2011-04-10 kinaba: LL D; 4bef2b4eaf 2011-04-10 kinaba: LL R; 4bef2b4eaf 2011-04-10 kinaba: bool operator<(const Problem& rhs) const { 4bef2b4eaf 2011-04-10 kinaba: if(R != rhs.R) return R < rhs.R; 4bef2b4eaf 2011-04-10 kinaba: if(D != rhs.D) return D > rhs.D; 4bef2b4eaf 2011-04-10 kinaba: return M > rhs.M; 4bef2b4eaf 2011-04-10 kinaba: } 4bef2b4eaf 2011-04-10 kinaba: }; 4bef2b4eaf 2011-04-10 kinaba: int find(int T, vector <int> maxPoints, vector <int> pointsPerMinute, vector <int> requiredTime) 4bef2b4eaf 2011-04-10 kinaba: { 4bef2b4eaf 2011-04-10 kinaba: const int N = maxPoints.size(); 4bef2b4eaf 2011-04-10 kinaba: vector<Problem> ps; 4bef2b4eaf 2011-04-10 kinaba: for(int i=0; i<N; ++i) { 4bef2b4eaf 2011-04-10 kinaba: Problem p = {maxPoints[i], pointsPerMinute[i], requiredTime[i]}; 4bef2b4eaf 2011-04-10 kinaba: ps.push_back(p); 4bef2b4eaf 2011-04-10 kinaba: } 4bef2b4eaf 2011-04-10 kinaba: sort(ps.begin(), ps.end()); 4bef2b4eaf 2011-04-10 kinaba: 4bef2b4eaf 2011-04-10 kinaba: LL best = 0; 4bef2b4eaf 2011-04-10 kinaba: 4bef2b4eaf 2011-04-10 kinaba: map<LL, LL> st; 4bef2b4eaf 2011-04-10 kinaba: st[0] = 0; 4bef2b4eaf 2011-04-10 kinaba: for(int i=0; i<N; ++i) 4bef2b4eaf 2011-04-10 kinaba: { 4bef2b4eaf 2011-04-10 kinaba: map<LL, LL> st2 = st; 4bef2b4eaf 2011-04-10 kinaba: for(map<LL, LL>::iterator it=st.begin(); it!=st.end(); ++it) 4bef2b4eaf 2011-04-10 kinaba: { 4bef2b4eaf 2011-04-10 kinaba: LL s = it->first; 4bef2b4eaf 2011-04-10 kinaba: LL t = it->second; 4bef2b4eaf 2011-04-10 kinaba: LL t2 = t + ps[i].R; 4bef2b4eaf 2011-04-10 kinaba: if( t2 <= T ) { 4bef2b4eaf 2011-04-10 kinaba: LL s2 = s + ps[i].M - ps[i].D * t2; 4bef2b4eaf 2011-04-10 kinaba: best = max(best, s2); 4bef2b4eaf 2011-04-10 kinaba: if( s2 > s ) { 4bef2b4eaf 2011-04-10 kinaba: LL& entry = st2[s2]; 4bef2b4eaf 2011-04-10 kinaba: if( entry==0 || entry>t2 ) 4bef2b4eaf 2011-04-10 kinaba: entry = t2; 4bef2b4eaf 2011-04-10 kinaba: } 4bef2b4eaf 2011-04-10 kinaba: } 4bef2b4eaf 2011-04-10 kinaba: } 4bef2b4eaf 2011-04-10 kinaba: st.swap(st2); 4bef2b4eaf 2011-04-10 kinaba: } 4bef2b4eaf 2011-04-10 kinaba: return int(best); 4bef2b4eaf 2011-04-10 kinaba: } 4bef2b4eaf 2011-04-10 kinaba: }; 4bef2b4eaf 2011-04-10 kinaba: 4bef2b4eaf 2011-04-10 kinaba: // BEGIN CUT HERE 4bef2b4eaf 2011-04-10 kinaba: #include <ctime> 4bef2b4eaf 2011-04-10 kinaba: double start_time; string timer() 4bef2b4eaf 2011-04-10 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 4bef2b4eaf 2011-04-10 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 4bef2b4eaf 2011-04-10 kinaba: { os << "{ "; 4bef2b4eaf 2011-04-10 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 4bef2b4eaf 2011-04-10 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 4bef2b4eaf 2011-04-10 kinaba: void verify_case(const int& Expected, const int& Received) { 4bef2b4eaf 2011-04-10 kinaba: bool ok = (Expected == Received); 4bef2b4eaf 2011-04-10 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 4bef2b4eaf 2011-04-10 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 4bef2b4eaf 2011-04-10 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 4bef2b4eaf 2011-04-10 kinaba: #define END verify_case(_, TheProgrammingContestDivOne().find(T, maxPoints, pointsPerMinute, requiredTime));} 4bef2b4eaf 2011-04-10 kinaba: int main(){ 4bef2b4eaf 2011-04-10 kinaba: 4bef2b4eaf 2011-04-10 kinaba: CASE(0) 4bef2b4eaf 2011-04-10 kinaba: int T = 74; 4bef2b4eaf 2011-04-10 kinaba: int maxPoints_[] = {502}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); 4bef2b4eaf 2011-04-10 kinaba: int pointsPerMinute_[] = {2}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); 4bef2b4eaf 2011-04-10 kinaba: int requiredTime_[] = {47}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); 4bef2b4eaf 2011-04-10 kinaba: int _ = 408; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: CASE(1) 4bef2b4eaf 2011-04-10 kinaba: int T = 40000; 4bef2b4eaf 2011-04-10 kinaba: int maxPoints_[] = {100000, 100000}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); 4bef2b4eaf 2011-04-10 kinaba: int pointsPerMinute_[] = {1, 100000}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); 4bef2b4eaf 2011-04-10 kinaba: int requiredTime_[] = {50000, 30000}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); 4bef2b4eaf 2011-04-10 kinaba: int _ = 0; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: CASE(2) 4bef2b4eaf 2011-04-10 kinaba: int T = 75; 4bef2b4eaf 2011-04-10 kinaba: int maxPoints_[] = {250, 500, 1000}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); 4bef2b4eaf 2011-04-10 kinaba: int pointsPerMinute_[] = {2, 4, 8}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); 4bef2b4eaf 2011-04-10 kinaba: int requiredTime_[] = {25, 25, 25}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); 4bef2b4eaf 2011-04-10 kinaba: int _ = 1200; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: CASE(3) 4bef2b4eaf 2011-04-10 kinaba: int T = 30; 4bef2b4eaf 2011-04-10 kinaba: int maxPoints_[] = {100, 100, 100000}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); 4bef2b4eaf 2011-04-10 kinaba: int pointsPerMinute_[] = {1, 1, 100}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); 4bef2b4eaf 2011-04-10 kinaba: int requiredTime_[] = {15, 15, 30}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); 4bef2b4eaf 2011-04-10 kinaba: int _ = 97000; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: CASE(4) 4bef2b4eaf 2011-04-10 kinaba: int T = 100000; 4bef2b4eaf 2011-04-10 kinaba: 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,}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); 4bef2b4eaf 2011-04-10 kinaba: 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,}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); 4bef2b4eaf 2011-04-10 kinaba: 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}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); 4bef2b4eaf 2011-04-10 kinaba: int _ = -1; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: CASE(5) 4bef2b4eaf 2011-04-10 kinaba: int T = 100000; 4bef2b4eaf 2011-04-10 kinaba: 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,}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); 4bef2b4eaf 2011-04-10 kinaba: 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}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); 4bef2b4eaf 2011-04-10 kinaba: 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}; 4bef2b4eaf 2011-04-10 kinaba: vector <int> requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); 4bef2b4eaf 2011-04-10 kinaba: int _ = -1; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: /* 4bef2b4eaf 2011-04-10 kinaba: CASE(5) 4bef2b4eaf 2011-04-10 kinaba: int T = ; 4bef2b4eaf 2011-04-10 kinaba: int maxPoints_[] = ; 4bef2b4eaf 2011-04-10 kinaba: vector <int> maxPoints(maxPoints_, maxPoints_+sizeof(maxPoints_)/sizeof(*maxPoints_)); 4bef2b4eaf 2011-04-10 kinaba: int pointsPerMinute_[] = ; 4bef2b4eaf 2011-04-10 kinaba: vector <int> pointsPerMinute(pointsPerMinute_, pointsPerMinute_+sizeof(pointsPerMinute_)/sizeof(*pointsPerMinute_)); 4bef2b4eaf 2011-04-10 kinaba: int requiredTime_[] = ; 4bef2b4eaf 2011-04-10 kinaba: vector <int> requiredTime(requiredTime_, requiredTime_+sizeof(requiredTime_)/sizeof(*requiredTime_)); 4bef2b4eaf 2011-04-10 kinaba: int _ = ; 4bef2b4eaf 2011-04-10 kinaba: END 4bef2b4eaf 2011-04-10 kinaba: */ 4bef2b4eaf 2011-04-10 kinaba: } 4bef2b4eaf 2011-04-10 kinaba: // END CUT HERE