ADDED SRM/697-U/1A-U.cpp Index: SRM/697-U/1A-U.cpp ================================================================== --- SRM/697-U/1A-U.cpp +++ SRM/697-U/1A-U.cpp @@ -0,0 +1,92 @@ +#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 DivisibleSetDiv1 { public: + string isPossible(vector b) + { + return solve(b) ? "Possible" : "Impossible"; + } + + bool solve(vector b) + { + sort(b.begin(), b.end()); + int n = b.size(); + + int sum = 0; + for(int i=0; i (b[i]+1)*(n-i)) + return false; + return true; + } +}; + +// 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(_, DivisibleSetDiv1().isPossible(b));} +int main(){ + +CASE(0) + int b_[] = {2,1}; + vector b(b_, b_+sizeof(b_)/sizeof(*b_)); + string _ = "Possible"; +END +CASE(1) + int b_[] = {1,1}; + vector b(b_, b_+sizeof(b_)/sizeof(*b_)); + string _ = "Impossible"; +END +CASE(2) + int b_[] = {7, 7, 7}; + vector b(b_, b_+sizeof(b_)/sizeof(*b_)); + string _ = "Possible"; +END +CASE(3) + int b_[] = {5,3,5,4,6,1,3,7,9,6,2,5,4,1,1,9,6,10,10,6,10,7,7,8}; + vector b(b_, b_+sizeof(b_)/sizeof(*b_)); + string _ = "Impossible"; +END +CASE(4) + int b_[] = {2,3,4}; + vector b(b_, b_+sizeof(b_)/sizeof(*b_)); + string _ = "Possible"; +END +/* +CASE(5) + int b_[] = ; + vector b(b_, b_+sizeof(b_)/sizeof(*b_)); + string _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/697-U/1B.cpp Index: SRM/697-U/1B.cpp ================================================================== --- SRM/697-U/1B.cpp +++ SRM/697-U/1B.cpp @@ -0,0 +1,136 @@ +#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; + +static const unsigned MODVAL = 1000000007; + +class XorOrderDiv1 { public: + int get(int m, int n, int a0, int b) + { + vector a; + for(int i=0; i& A, int M) + { + vector d; + return solve_rec(A, 0, A.size(), M-1, d); + } + + int solve_rec(const vector& A, int s, int e, int bit, vector& d) + { + if(s==e) + return 0; + + if(bit == -1) { + const int M = d.size(); + LL q = 0; + LL sigma = 0; + for(int m=M-1; m>=0; --m) + { + LL qprev = q; + LL dd = d[m]; + q = dd*dd%MODVAL*(1LL<<(M-m-1)) + sigma*dd%MODVAL*(1LL<<(M-m-1)) + 2*qprev; + sigma += dd; + } + return int(q % MODVAL); + } + + int m=s; + for(; m +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(_, XorOrderDiv1().get(m, n, a0, b));} +int main(){ + +CASE(0) + int m = 2; + int n = 3; + int a0 = 0; + int b = 1; + int _ = 8; +END +CASE(1) + int m = 3; + int n = 5; + int a0 = 1; + int b = 3; + int _ = 48; +END +CASE(2) + int m = 16; + int n = 100; + int a0 = 41; + int b = 5; + int _ = 523436032; +END +CASE(3) + int m = 30; + int n = 200000; + int a0 = 399; + int b = 18082016; + int _ = 408585698; +END +/* +CASE(4) + int m = ; + int n = ; + int a0 = ; + int b = ; + int _ = ; +END +CASE(5) + int m = ; + int n = ; + int a0 = ; + int b = ; + int _ = ; +END +*/ +} +// END CUT HERE