ADDED SRM/662-U/1A.cpp Index: SRM/662-U/1A.cpp ================================================================== --- SRM/662-U/1A.cpp +++ SRM/662-U/1A.cpp @@ -0,0 +1,123 @@ +#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; + +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<<28)); } + T& operator()(int i1, int i2) + { return data[ (i1*N2)+i2 ]; } + void swap(DP2& rhs) + { data.swap(rhs.data); } +}; + +class FoxesOfTheRoundTable { public: + vector minimalDifference(vector h) + { + const int N = h.size(); + vector idx(N); + for(int i=0; i aa(1, 0), bb(1, 0); + for(int k=1; k ans; + for(auto a: aa) + ans.push_back(idx[a]); + bb.push_back(N-1); + reverse(bb.begin(), bb.end()); + bb.pop_back(); + for(auto b: bb) + ans.push_back(idx[b]); + + 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 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(_, FoxesOfTheRoundTable().minimalDifference(h));} +int main(){ + +CASE(0) + int h_[] = {1,99,50,50}; + vector h(h_, h_+sizeof(h_)/sizeof(*h_)); + int __[] = {0, 3, 1, 2 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(1) + int h_[] = {123,456,789}; + vector h(h_, h_+sizeof(h_)/sizeof(*h_)); + int __[] = {0, 1, 2 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(2) + int h_[] = {10,30,40,50,60}; + vector h(h_, h_+sizeof(h_)/sizeof(*h_)); + int __[] = {0, 1, 4, 3, 2 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(3) + int h_[] = {1,2,3,4,8,12,13,14 }; + vector h(h_, h_+sizeof(h_)/sizeof(*h_)); + int __[] = {0, 1, 2, 3, 5, 6, 7, 4 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(4) + int h_[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }; + vector h(h_, h_+sizeof(h_)/sizeof(*h_)); + int __[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +/* +CASE(5) + int h_[] = ; + vector h(h_, h_+sizeof(h_)/sizeof(*h_)); + int __[] = ; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(6) + int h_[] = ; + vector h(h_, h_+sizeof(h_)/sizeof(*h_)); + int __[] = ; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +*/ +} +// END CUT HERE