ADDED SRM/TCO16-2A-U/1A-U.cpp Index: SRM/TCO16-2A-U/1A-U.cpp ================================================================== --- SRM/TCO16-2A-U/1A-U.cpp +++ SRM/TCO16-2A-U/1A-U.cpp @@ -0,0 +1,195 @@ +#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 LCMGCD { public: + string isPossible(vector x, int t) + { + pair tt = crack(t); + vector> ab; + for(int xi: x) { + pair xx = crack(xi); + ab.emplace_back(sign(xx.first, tt.first), sign(xx.second, tt.second)); + } + return solve(ab) ? "Possible" : "Impossible"; + } + + pair crack(int x) + { + int a=0, b=0; + while(x%2==0) x/=2, a++; + while(x%3==0) x/=3, b++; + return make_pair(a,b); + } + + int sign(int x, int t) + { + return x> x) + { + set> vis; + vector sig(7); + vis.insert(sig); + + for(auto ab: x) { + int s = ab.first*3 + ab.second; + if(0(7); goal[3]=1; + return rec(sig, vis); + } + + vector goal; + bool rec(vector& sig, set>& vis) + { + if(sig[3] >= 2) + return true; + if(sig == goal) + return true; + + if(vis.count(sig)) + return false; + vis.insert(sig); + + for(int a=1; a<8; ++a) if(sig[a-1]) + for(int b=a; b<8; ++b) if(sig[b-1]) { + if(b==a && sig[a-1]==1) continue; + sig[a-1]--; + sig[b-1]--; + int z = max(a/3,b/3)*3 + max(a%3,b%3); + if(0 +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(_, LCMGCD().isPossible(x, t));} +int main(){ + +CASE(0) + int x_[] = {2,3}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int t = 6; + string _ = "Possible"; +END +CASE(1) + int x_[] = {4,9}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int t = 6; + string _ = "Impossible"; +END +CASE(2) + int x_[] = {6,12,24,18,36,72,54,108,216}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int t = 36; + string _ = "Possible"; +END +CASE(3) + int x_[] = {6,27,81,729}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int t = 6; + string _ = "Impossible"; +END +CASE(4) + int x_[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int t = 1; + string _ = "Possible"; +END +CASE(5) + int x_[] = {72,16,16,16,16,16,27,27,27,27,27,27,27,27,27}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int t = 72; + string _ = "Possible"; +END +CASE(6) + int x_[] = {100663296, 544195584, 229582512, 59049}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int t = 60466176; + string _ = "Possible"; +END +CASE(7) + int x_[] = {2,4,8,16,32,64}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int t = 256; + string _ = "Impossible"; +END +CASE(8) + int x_[] = {6,9}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int t = 6; + string _ = "Impossible"; +END +CASE(9) + int x_[] = {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, + 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int t = 6; + string _ = "Impossible"; +END +CASE(8) + int x_[] = {6,6,9}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int t = 6; + string _ = "Possible"; +END +CASE(8) + int x_[] = {9,18,12}; + vector x(x_, x_+sizeof(x_)/sizeof(*x_)); + int t = 6; + string _ = "Possible"; +END +} +// END CUT HERE