ADDED SRM/605-U/1A.cpp Index: SRM/605-U/1A.cpp ================================================================== --- SRM/605-U/1A.cpp +++ SRM/605-U/1A.cpp @@ -0,0 +1,118 @@ +#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; + +class AlienAndHamburgers { public: + int getNumber(vector type, vector taste) + { + const int N = type.size(); + + vector> taste_type; + for(int i=0; i Y; + int A = 0; + for(auto& tt: taste_type) { + int ta = tt.first; + int ty = tt.second; + if(ta >= 0 || !Y.count(ty)) { + Y.insert(ty); + A += ta; + } + best = max(best, Y.size()*A); + } + + return best; + } +}; + +// 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(_, AlienAndHamburgers().getNumber(type, taste));} +int main(){ + +CASE(0) + int type_[] = {1, 2}; + vector type(type_, type_+sizeof(type_)/sizeof(*type_)); + int taste_[] = {4, 7}; + vector taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); + int _ = 22; +END +CASE(1) + int type_[] = {1, 1}; + vector type(type_, type_+sizeof(type_)/sizeof(*type_)); + int taste_[] = {-1, -1}; + vector taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); + int _ = 0; +END +CASE(2) + int type_[] = {1, 2, 3}; + vector type(type_, type_+sizeof(type_)/sizeof(*type_)); + int taste_[] = {7, 4, -1}; + vector taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); + int _ = 30; +END +CASE(3) + int type_[] = {1, 2, 3, 2, 3, 1, 3, 2, 3, 1, 1, 1}; + vector type(type_, type_+sizeof(type_)/sizeof(*type_)); + int taste_[] = {1, 7, -2, 3, -4, -1, 3, 1, 3, -5, -1, 0}; + vector taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); + int _ = 54; +END +CASE(4) + int type_[] = {30, 20, 10}; + vector type(type_, type_+sizeof(type_)/sizeof(*type_)); + int taste_[] = {100000, -100000, 100000}; + vector taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); + int _ = 400000; +END +CASE(5) + int type_[] = {1,2,4,4,3}; + vector type(type_, type_+sizeof(type_)/sizeof(*type_)); + int taste_[] = {100,100,-1,-1,-1}; + vector taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); + int _ = 792; +END +/* +CASE(6) + int type_[] = ; + vector type(type_, type_+sizeof(type_)/sizeof(*type_)); + int taste_[] = ; + vector taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/605-U/1B.cpp Index: SRM/605-U/1B.cpp ================================================================== --- SRM/605-U/1B.cpp +++ SRM/605-U/1B.cpp @@ -0,0 +1,115 @@ +#include +#include +#include +#include +using namespace std; + +static const unsigned MODVAL = 1000000007; +struct mint +{ + unsigned val; + mint():val(0){} + mint(int x):val(x%MODVAL) {} + mint(unsigned x):val(x%MODVAL) {} +}; +mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } + +class AlienAndSetDiv1 { public: + int getNumber(int N, int K) + { + memo.assign((1< A, B; + return rec(N, K, A, B, 0); + } + + vector memo; + int rec(size_t N, int K, vector& A, vector& B, int lastk) + { + if(A.size()==N && B.size()==N) + return 1; + + auto key = (lastk*(N+1)+A.size())*(N+1)+B.size(); + if(memo[key] >= 0) + return memo[key]; + + int next = A.size()+B.size()+1, nextmask = (lastk &~ (1<<(K-1)))<<1; + int ai = A.size(), bi = B.size(); + + mint total = 0; + + A.push_back(next); + if(A.size()<=N && (ai>=B.size() || abs(A[ai]-B[ai])>=K)) + total += rec(N, K, A, B, nextmask); + A.pop_back(); + B.push_back(next); + if(B.size()<=N && (bi>=A.size() || abs(A[bi]-B[bi])>=K)) + total += rec(N, K, A, B, nextmask|1); + B.pop_back(); + + return memo[key] = total.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(_, AlienAndSetDiv1().getNumber(N, K));} +int main(){ + +CASE(0) + int N = 2; + int K = 2; + int _ = 2; +END +CASE(1) + int N = 3; + int K = 1; + int _ = 20; +END +CASE(2) + int N = 4; + int K = 2; + int _ = 14; +END +CASE(3) + int N = 10; + int K = 7; + int _ = 40; +END +CASE(4) + int N = 50; + int K = 10; + int _ = -1; +END +CASE(5) + int N = 50; + int K = 1; + int _ = -1; +END +CASE(5) + int N = 50; + int K = 2; + int _ = -1; +END +CASE(5) + int N = 50; + int K = 4; + int _ = -1; +END +CASE(5) + int N = 2; + int K = 2; + int _ = 2; +END +} +// END CUT HERE