ADDED SRM/524-U/1A.cpp Index: SRM/524-U/1A.cpp ================================================================== --- SRM/524-U/1A.cpp +++ SRM/524-U/1A.cpp @@ -0,0 +1,83 @@ +#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 MagicDiamonds { public: + long long minimalTransfer(long long n) + { + if( n <= 3 ) + return n; + for(LL p=2; p*p<=n && p +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(_, MagicDiamonds().minimalTransfer(n));} +int main(){ + +CASE(0) + long long n = 2LL; + long long _ = 2LL; +END +CASE(1) + long long n = 4294967297LL; + long long _ = 1LL; +END +CASE(2) + long long n = 2147483647LL; + long long _ = 2LL; +END +CASE(3) + long long n = 1LL; + long long _ = 1LL; +END +CASE(4) + long long n = 1000000000000LL; + long long _ = -1LL; +END +/* +CASE(5) + long long n = LL; + long long _ = LL; +END +*/ +} +// END CUT HERE ADDED SRM/524-U/1B.cpp Index: SRM/524-U/1B.cpp ================================================================== --- SRM/524-U/1B.cpp +++ SRM/524-U/1B.cpp @@ -0,0 +1,125 @@ +#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 LongestSequence { public: + int maxLength(vector C) + { + vector P, N; + for(int i=0; i 1 ) { + int C = (L+R)/2; + (has_loop(N, P, C) ? R : L) = C; + } + return L; + } + + bool has_loop(const vector& N, const vector& P, int MAX) + { + vector vis(MAX+1, false); + queue Q; + Q.push(0); + vis[0] = true; + while( !Q.empty() ) { + int v = Q.front(); + Q.pop(); + for(int i=0; i 0 && !vis[v-N[i]] ) + {vis[v-N[i]]=true; Q.push(v-N[i]);} + 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 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(_, LongestSequence().maxLength(C));} +int main(){ + +CASE(0) + int C_[] = {-2,3}; + vector C(C_, C_+sizeof(C_)/sizeof(*C_)); + int _ = 3; +END +CASE(1) + int C_[] = {524}; + vector C(C_, C_+sizeof(C_)/sizeof(*C_)); + int _ = -1; +END +CASE(2) + int C_[] = {1, -1}; + vector C(C_, C_+sizeof(C_)/sizeof(*C_)); + int _ = 0; +END +CASE(3) + int C_[] = {11,-7}; + vector C(C_, C_+sizeof(C_)/sizeof(*C_)); + int _ = 16; +END +CASE(4) + int C_[] = {-227,690,590,-524}; + vector C(C_, C_+sizeof(C_)/sizeof(*C_)); + int _ = 713; +END +CASE(5) + int C_[] = {273,752,-738,-34,863,-21,-532,-824,-170,-130,206,346,836,149,-374,-807,55,-859,640,-103,266,-716,963,-274,-654,-429,-512,595,-253,-32,790,-884,-974,975,-493,-979,-548,423,-242,-443,-132,-868,-374,-854,-15,476,-950,968,740,799}; + vector C(C_, C_+sizeof(C_)/sizeof(*C_)); + int _ = -1; +END +CASE(6) + int C_[] = {3,4,3,3,1,4,4,-5,3,1,5,5,3,2,-1,-5,-4,2,-4,2,-2,-2,1,-5,4,-3,-3,4,2,-1,2,-4,1,4,-4,-2,4,-5,0,-4,5,3,-5,1,0,0,4,5,-5,-5}; + vector C(C_, C_+sizeof(C_)/sizeof(*C_)); + int _ = -1; +END + +} +// END CUT-1000 HERE ADDED SRM/524-U/1C-U.cpp Index: SRM/524-U/1C-U.cpp ================================================================== --- SRM/524-U/1C-U.cpp +++ SRM/524-U/1C-U.cpp @@ -0,0 +1,187 @@ +#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; + +static const int MODVAL = 1000000009; // must be prime for op/ +struct mint +{ + int val; + mint():val(0){} + mint(int x):val(x%MODVAL) {} // x>=0 + mint(size_t x):val(x%MODVAL) {} // x>=0 + mint(LL x):val(x%MODVAL) {} // x>=0 +}; +mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } +mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } +mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } +mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; } +mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); } +mint operator+(mint x, mint y) { return x+=y; } +mint operator-(mint x, mint y) { return x-=y; } +mint operator*(mint x, mint y) { return x*=y; } +mint operator/(mint x, mint y) { return x/=y; } +vector FAC_(1,1); +mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*FAC_.size() ); return FAC_[n]; } +mint C(LL n, LL k) { return k<0 || n left, vector front) + { + mint ans = 1; + sort(left.begin(), left.end()); + sort(front.begin(), front.end()); + ans *= perm(left); + ans *= perm(front); + for(int i=0, k=0; i& x) + { + map cat; + for(int i=0; i::iterator it=cat.begin(); it!=cat.end(); ++it) + r /= FAC(it->second); + return r; + } + + mint choose(int h, int n) + { + mint r = 0; + for(int k=1; k<=n; ++k) + r += C(n, k) * POW(h, n-k); + return r; + } + + mint choose2(int h, int n1, int n2) + { + return POW(2, n1+n2) + h * choose(h,n1) * choose(h,n2); + } +}; + +// 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(_, AxonometricProjection().howManyWays(heightsOfLeftView, heightsOfFrontView));} +int main(){ + +CASE(0) + int heightsOfLeftView_[] = {1,1}; + vector heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_)); + int heightsOfFrontView_[] = {1,1}; + vector heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_)); + int _ = 7; +END +CASE(1) + int heightsOfLeftView_[] = {50,50,50,50,524}; + vector heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_)); + int heightsOfFrontView_[] = {524,524}; + vector heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_)); + int _ = 104060401; +END +CASE(2) + int heightsOfLeftView_[] = {1,2,3,4,5,6,7,8,9,10}; + vector heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_)); + int heightsOfFrontView_[] = {1,2,3,4,5,6,7,8,9,10,11}; + vector heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_)); + int _ = 0; +END +CASE(3) + int heightsOfLeftView_[] = {5,2,4,1}; + vector heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_)); + int heightsOfFrontView_[] = {5,2,4,0,1}; + vector heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_)); + int _ = 429287; +END +CASE(4) + int heightsOfLeftView_[] = {5,2,4,52,24,524}; + vector heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_)); + int heightsOfFrontView_[] = {0,4,20,24,500,504,520,524}; + vector heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_)); + int _ = 97065655; +END +/* +CASE(5) + int heightsOfLeftView_[] = ; + vector heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_)); + int heightsOfFrontView_[] = ; + vector heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_)); + int _ = ; +END +CASE(6) + int heightsOfLeftView_[] = ; + vector heightsOfLeftView(heightsOfLeftView_, heightsOfLeftView_+sizeof(heightsOfLeftView_)/sizeof(*heightsOfLeftView_)); + int heightsOfFrontView_[] = ; + vector heightsOfFrontView(heightsOfFrontView_, heightsOfFrontView_+sizeof(heightsOfFrontView_)/sizeof(*heightsOfFrontView_)); + int _ = ; +END +*/ +} +// END CUT HERE