ADDED SRM/620-U/1A-U.cpp Index: SRM/620-U/1A-U.cpp ================================================================== --- SRM/620-U/1A-U.cpp +++ SRM/620-U/1A-U.cpp @@ -0,0 +1,124 @@ +#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 PairGame { public: + int maxSum(int a, int b, int c, int d) + { + vector> s1 = seq(a,b); + vector> s2 = seq(c,d); + int cand = -1; + for(auto& p1: s1) + for(auto& p2: s2) + if(p1 == p2) + cand = max(cand, p1.first + p1.second); + return cand; + } + + vector> seq(int a, int b) + { + vector> s; + do { + s.emplace_back(a, b); + if(a +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(_, PairGame().maxSum(a, b, c, d));} +int main(){ + +CASE(0) + int a = 1; + int b = 2; + int c = 2; + int d = 1; + int _ = 2; +END +CASE(1) + int a = 15; + int b = 4; + int c = 10; + int d = 7; + int _ = 7; +END +CASE(2) + int a = 1; + int b = 1; + int c = 10; + int d = 10; + int _ = -1; +END +CASE(3) + int a = 1000; + int b = 1001; + int c = 2000; + int d = 2001; + int _ = 1001; +END +CASE(4) + int a = 10944; + int b = 17928; + int c = 7704; + int d = 21888; + int _ = 144; +END +CASE(5) + int a = 1; + int b = 1; + int c = 1; + int d = 1; + int _ = 2; +END +/* +CASE(6) + int a = ; + int b = ; + int c = ; + int d = ; + int _ = ; +END +CASE(7) + int a = ; + int b = ; + int c = ; + int d = ; + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/620-U/1B.cpp Index: SRM/620-U/1B.cpp ================================================================== --- SRM/620-U/1B.cpp +++ SRM/620-U/1B.cpp @@ -0,0 +1,159 @@ +#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 CandidatesSelection { public: + string possible(vector score, vector result) + { + return solve(score, result) ? "Possible" : "Impossible"; + } + + bool solve(vector score, vector result) + { + const int N = score.size(); + const int S = score[0].size(); + + // po[a][b] : bitmask of skill set that makes a> po(N, vector(N)); + for(int a=0; a> now(1, result); + + function>)> rec; + rec = [&](LL used, vector> obl) { + LL pos = ~0LL; + for(auto& oi: obl) + for(int i=0; i+1> next; + for(auto& oi: obl) { + vector cur; + for(int o: oi) { + if(!cur.empty() && score[cur.back()][s] < score[o][s]) { + changed = true; + if(cur.size()>=2) + next.push_back(cur); + cur.clear(); + } + cur.push_back(o); + } + if(cur.size()>=2) + next.push_back(cur); + } + obl = std::move(next); + } + return changed && rec(used|pos, obl); + }; + return rec(0, now); + } + +}; + +// 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 string& Expected, const string& 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(_, CandidatesSelection().possible(score, result));} +int main(){ + +CASE(0) + string score_[] = {"CC", "AA", "BB"}; + vector score(score_, score_+sizeof(score_)/sizeof(*score_)); + int result_[] = {1,2,0}; + vector result(result_, result_+sizeof(result_)/sizeof(*result_)); + string _ = "Possible"; +END +CASE(1) + string score_[] = {"BAB", "ABB", "AAB", "ABA"}; + vector score(score_, score_+sizeof(score_)/sizeof(*score_)); + int result_[] = {2,0,1,3}; + vector result(result_, result_+sizeof(result_)/sizeof(*result_)); + string _ = "Possible"; +END +CASE(2) + string score_[] = {"BAB", "ABB", "AAB", "ABA"}; + vector score(score_, score_+sizeof(score_)/sizeof(*score_)); + int result_[] = {0, 1, 3, 2}; + vector result(result_, result_+sizeof(result_)/sizeof(*result_)); + string _ = "Impossible"; +END +CASE(3) + string score_[] = {"AAA", "ZZZ"}; + vector score(score_, score_+sizeof(score_)/sizeof(*score_)); + int result_[] = {1, 0}; + vector result(result_, result_+sizeof(result_)/sizeof(*result_)); + string _ = "Impossible"; +END +CASE(4) + string score_[] = {"ZZZ", "AAA"}; + vector score(score_, score_+sizeof(score_)/sizeof(*score_)); + int result_[] = {0, 1}; + vector result(result_, result_+sizeof(result_)/sizeof(*result_)); + string _ = "Possible"; +END +CASE(5) + string score_[] = {"ZYYYYX","YXZYXY","ZZZZXX","XZXYYX","ZZZYYZ","ZZXXYZ","ZYZZXZ","XZYYZX"}; + vector score(score_, score_+sizeof(score_)/sizeof(*score_)); + int result_[] = {3,7,1,0,2,5,6,4}; + vector result(result_, result_+sizeof(result_)/sizeof(*result_)); + string _ = "Possible"; +END +/* +CASE(6) + string score_[] = ; + vector score(score_, score_+sizeof(score_)/sizeof(*score_)); + int result_[] = ; + vector result(result_, result_+sizeof(result_)/sizeof(*result_)); + string _ = ; +END +CASE(7) + string score_[] = ; + vector score(score_, score_+sizeof(score_)/sizeof(*score_)); + int result_[] = ; + vector result(result_, result_+sizeof(result_)/sizeof(*result_)); + string _ = ; +END +*/ +} +// END CUT HERE