ADDED SRM/530-U/2A.cpp Index: SRM/530-U/2A.cpp ================================================================== --- SRM/530-U/2A.cpp +++ SRM/530-U/2A.cpp @@ -0,0 +1,102 @@ +#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 GogoXBallsAndBinsEasy { public: + int solve(vector T) + { + int maxMove = 0; + + vector S = T; + + reverse(S.begin(), S.end()); + int dif = 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 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(_, GogoXBallsAndBinsEasy().solve(T));} +int main(){ + +CASE(0) + int T_[] = {0, 2, 5}; + vector T(T_, T_+sizeof(T_)/sizeof(*T_)); + int _ = 5; +END +CASE(1) + int T_[] = {5, 6, 7, 8}; + vector T(T_, T_+sizeof(T_)/sizeof(*T_)); + int _ = 4; +END +CASE(2) + int T_[] = {0, 1, 2, 10}; + vector T(T_, T_+sizeof(T_)/sizeof(*T_)); + int _ = 11; +END +CASE(3) + int T_[] = {1, 2, 3, 4, 5, 6, 7, 8}; + vector T(T_, T_+sizeof(T_)/sizeof(*T_)); + int _ = 16; +END +/* +CASE(4) + int T_[] = ; + vector T(T_, T_+sizeof(T_)/sizeof(*T_)); + int _ = ; +END +CASE(5) + int T_[] = ; + vector T(T_, T_+sizeof(T_)/sizeof(*T_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/531-U/1A.cpp Index: SRM/531-U/1A.cpp ================================================================== --- SRM/531-U/1A.cpp +++ SRM/531-U/1A.cpp @@ -0,0 +1,144 @@ +#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 = 1000000007; // 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 heard(N+1, 0); + heard[r] = Perm(N, r); + for(int i=0; i h2(N+1, 0); + for(int x=0; x<=N; ++x) { + if(x>=M) + h2[x] += heard[x] * (x-M); + if(x +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(_, NoRepeatPlaylist().numPlaylists(N, M, P));} +int main(){ + +CASE(0) + int N = 1; + int M = 0; + int P = 3; + int _ = 1; +END +CASE(1) + int N = 1; + int M = 1; + int P = 3; + int _ = 0; +END +CASE(2) + int N = 2; + int M = 0; + int P = 3; + int _ = 6; +END +CASE(3) + int N = 4; + int M = 0; + int P = 4; + int _ = 24; +END +CASE(4) + int N = 2; + int M = 1; + int P = 4; + int _ = 2; +END +CASE(5) + int N = 50; + int M = 5; + int P = 100; + int _ = 222288991; +END +/* +CASE(6) + int N = ; + int M = ; + int P = ; + int _ = ; +END +CASE(7) + int N = ; + int M = ; + int P = ; + int _ = ; +END +*/ +} +// END CUT HERE