ADDED SRM/532-U/1A.cpp Index: SRM/532-U/1A.cpp ================================================================== --- SRM/532-U/1A.cpp +++ SRM/532-U/1A.cpp @@ -0,0 +1,152 @@ +#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 DengklekMakingChains { public: + int maxBeauty(vector chains) + { + int best = 0; + for(int C=0; C +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(_, DengklekMakingChains().maxBeauty(chains));} +int main(){ + +CASE(0) + string chains_[] = {".15", "7..", "402", "..3"}; + vector chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); + int _ = 19; + // .15 402 7.. +END +CASE(1) + string chains_[] = {"..1", "7..", "567", "24.", "8..", "234"}; + vector chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); + int _ = 36; + // ..1 567 234 8.. +END +CASE(2) + string chains_[] = {"...", "..."}; + vector chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); + int _ = 0; +END +CASE(3) + string chains_[] = {"16.", "9.8", ".24", "52.", "3.1", "532", "4.4", "111"}; + vector chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); + int _ = 28; + // .24 532 111 9.8 + // or + // 9.8 532 111 16. +END +CASE(4) + string chains_[] = {"..1", "3..", "2..", ".7."}; + vector chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); + int _ = 7; + // .7. +END +CASE(5) + string chains_[] = {"412", "..7", ".58", "7.8", "32.", "6..", "351", "3.9", "985", "...", ".46"}; + vector chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); + int _ = 58; + // .58 412 351 985 7.8 +END +CASE(6) + string chains_[] = {"9..", "..9"}; + vector chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); + int _ = 18; +END +CASE(7) + string chains_[] = {"..1"}; + vector chains(chains_, chains_+sizeof(chains_)/sizeof(*chains_)); + int _ = 1; +END +} +// END CUT HERE ADDED SRM/532-U/1B.cpp Index: SRM/532-U/1B.cpp ================================================================== --- SRM/532-U/1B.cpp +++ SRM/532-U/1B.cpp @@ -0,0 +1,145 @@ +#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; +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+=y; } + +template +struct DP4 +{ + int N1, N2, N3, N4; + vector data; + DP4(int N1, int N2, int N3, int N4, const T& t = T()) + : N1(N1), N2(N2), N3(N3), N4(N4), data(N1*N2*N3*N4, t) { assert(data.size()*sizeof(T)<(1<<26)); } + T& operator()(int i1, int i2, int i3, int i4) + { return data[ (((i1*N2)+i2)*N3+i3)*N4+i4 ]; } + void swap(DP4& rhs) + { data.swap(rhs.data); } +}; + +class DengklekBuildingRoads { public: + int numWays(int N, int M, int K) + { + DP4 dp(N, M+1, 1<=0; --a) + for(int e=0; e<=M; ++e) + for(int mask=0; mask<(1<=0; --b) + { + mint v = 0; + // draw edge + if(e && a+b+1>1,0); + } else { + if( mask==0 && e==0 ) + v += 1; + } + } + dp(a,e,mask,b) = v; + } + return dp(0,M,0,0).val; + } +}; + +// 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(_, DengklekBuildingRoads().numWays(N, M, K));} +int main(){ + +CASE(0) + int N = 3; + int M = 4; + int K = 1; + int _ = 3; +END +CASE(1) + int N = 4; + int M = 3; + int K = 3; + int _ = 4; +END +CASE(2) + int N = 2; + int M = 1; + int K = 1; + int _ = 0; +END +CASE(3) + int N = 5; + int M = 0; + int K = 3; + int _ = 1; +END +CASE(4) + int N = 10; + int M = 20; + int K = 5; + int _ = 26964424; +END +CASE(5) + int N = 1; + int M = 0; + int K = 1; + int _ = 1; +END +CASE(6) + int N = 30; + int M = 30; + int K = 8; + int _ = -1; +END + +} +// END CUT HERE