ADDED SRM/TCO12-2B-U/1A.cpp Index: SRM/TCO12-2B-U/1A.cpp ================================================================== --- SRM/TCO12-2B-U/1A.cpp +++ SRM/TCO12-2B-U/1A.cpp @@ -0,0 +1,121 @@ +#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 BlurredDartboard { public: + int minThrows(vector points, int P) + { + const int N = points.size(); + + int VisibleMax = *max_element(points.begin(), points.end()); + + vector hidden; + for(int x=1; x<=N; ++x) + if( count(points.begin(), points.end(), x) == 0 ) + hidden.push_back(x); + + int K = hidden.size(); + if( hidden.empty() || hidden.back() < VisibleMax ) + return (P+VisibleMax-1) / VisibleMax; + + partial_sum(hidden.begin(), hidden.end(), hidden.begin()); + vector vis; + for(int i=1; i<=K; ++i) + vis.push_back(i*VisibleMax); + + int turn = max(vis.back(), hidden.back()); + int n = (P/turn)*K; + if(P%turn) { + ++n; + for(int i=0; max(vis[i],hidden[i]) < (P%turn); ++i) + ++n; + } + return n; + } +}; + +// 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(_, BlurredDartboard().minThrows(points, P));} +int main(){ + +CASE(0) + int points_[] = {0, 3, 4, 0, 0}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int P = 8; + int _ = 2; +END +CASE(1) + int points_[] = {0, 0, 0, 0, 0}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int P = 15; + int _ = 5; +END +CASE(2) + int points_[] = {4, 7, 8, 1, 3, 2, 6, 5}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int P = 2012; + int _ = 252; +END +CASE(3) + int points_[] = {0, 0, 5, 0, 0, 0, 1, 3, 0, 0}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int P = 2012; + int _ = 307; +END +CASE(4) + int points_[] = {0, 2, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 6, 0, 0, 0, 4, 0, 0, 0}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int P = 1000000000; + int _ = 84656087; +END +CASE(5) +int points_[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int P = 1000000000; + int _ = -1; +END +/* +CASE(6) + int points_[] = ; + vector points(points_, points_+sizeof(points_)/sizeof(*points_)); + int P = ; + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/TCO12-2B-U/1B.cpp Index: SRM/TCO12-2B-U/1B.cpp ================================================================== --- SRM/TCO12-2B-U/1B.cpp +++ SRM/TCO12-2B-U/1B.cpp @@ -0,0 +1,185 @@ +#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 DP2 +{ + const int N1, N2; + vector data; + DP2(int N1, int N2, const T& t = T()) + : N1(N1), N2(N2), data(N1*N2, t) { assert(data.size()*sizeof(T)<(1<<26)); } + T& operator()(int i1, int i2) + { return data[ (i1*N2)+i2 ]; } + void swap(DP2& rhs) + { data.swap(rhs.data); } +}; + +class HeavyBooks { public: + vector findWeight(vector books, vector moves) + { + const int K = moves[0]; + + vector tomek, wojtek; + for(int i=0; i& fr = (i%2 == 0 ? tomek : wojtek); + vector& to = (i%2 == 0 ? wojtek : tomek); + for(int k=0; k for_tomek(K); + for(int i=0; i > dp(books.size(), K+1); + for(int i=0; i next(PrevDif+DifIncr, PrevSum+SumIncr); + if( dp(i,k) < next ) + dp(i,k) = next; + } + } + } + + int WminusT = dp(books.size()-1, K).first; + int WplusT = dp(books.size()-1, K).second; + vector answer; + answer.push_back( (WplusT - WminusT)/2 ); + answer.push_back( (WplusT + WminusT)/2 ); + return answer; + } +}; + +// 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(_, HeavyBooks().findWeight(books, moves));} +int main(){ + +CASE(0) + int books_[] = {5,2,3,1}; + vector books(books_, books_+sizeof(books_)/sizeof(*books_)); + int moves_[] = {3,2,1,1,1}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int __[] = {3, 7 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(1) + int books_[] = {10, 100, 1000}; + vector books(books_, books_+sizeof(books_)/sizeof(*books_)); + int moves_[] = {2, 3}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int __[] = {110, 0 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(2) + int books_[] = {155870,565381}; + vector books(books_, books_+sizeof(books_)/sizeof(*books_)); + int moves_[] = {1,1,1}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int __[] = {0, 565381 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(3) + int books_[] = {500,500,500,500}; + vector books(books_, books_+sizeof(books_)/sizeof(*books_)); + int moves_[] = {4,1,1,3,2}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int __[] = {500, 1500 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(4) + int books_[] = {1,1,1,1,1000000}; + vector books(books_, books_+sizeof(books_)/sizeof(*books_)); + int moves_[] = {1}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int __[] = {0, 1000000 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(5) + int books_[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; + vector books(books_, books_+sizeof(books_)/sizeof(*books_)); + int moves_[] = {20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int __[] = {110, 100 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +/* +CASE(6) + int books_[] = ; + vector books(books_, books_+sizeof(books_)/sizeof(*books_)); + int moves_[] = ; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int __[] = ; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(7) + int books_[] = ; + vector books(books_, books_+sizeof(books_)/sizeof(*books_)); + int moves_[] = ; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int __[] = ; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +*/ +} +// END CUT HERE