b9612fa18c 2014-04-19 kinaba: #include <iostream> b9612fa18c 2014-04-19 kinaba: #include <sstream> b9612fa18c 2014-04-19 kinaba: #include <iomanip> b9612fa18c 2014-04-19 kinaba: #include <vector> b9612fa18c 2014-04-19 kinaba: #include <string> b9612fa18c 2014-04-19 kinaba: #include <map> b9612fa18c 2014-04-19 kinaba: #include <set> b9612fa18c 2014-04-19 kinaba: #include <algorithm> b9612fa18c 2014-04-19 kinaba: #include <numeric> b9612fa18c 2014-04-19 kinaba: #include <iterator> b9612fa18c 2014-04-19 kinaba: #include <functional> b9612fa18c 2014-04-19 kinaba: #include <complex> b9612fa18c 2014-04-19 kinaba: #include <queue> b9612fa18c 2014-04-19 kinaba: #include <stack> b9612fa18c 2014-04-19 kinaba: #include <cmath> b9612fa18c 2014-04-19 kinaba: #include <cassert> b9612fa18c 2014-04-19 kinaba: #include <tuple> b9612fa18c 2014-04-19 kinaba: using namespace std; b9612fa18c 2014-04-19 kinaba: typedef long long LL; b9612fa18c 2014-04-19 kinaba: typedef complex<double> CMP; b9612fa18c 2014-04-19 kinaba: b9612fa18c 2014-04-19 kinaba: class AmebaDiv1 { public: b9612fa18c 2014-04-19 kinaba: int count(vector <int> X) b9612fa18c 2014-04-19 kinaba: { b9612fa18c 2014-04-19 kinaba: set<int> last(X.begin(), X.end()); b9612fa18c 2014-04-19 kinaba: int cnt = 0; b9612fa18c 2014-04-19 kinaba: for(int E : last) b9612fa18c 2014-04-19 kinaba: if(!can_end_by(X, E)) b9612fa18c 2014-04-19 kinaba: ++cnt; b9612fa18c 2014-04-19 kinaba: return cnt; b9612fa18c 2014-04-19 kinaba: } b9612fa18c 2014-04-19 kinaba: b9612fa18c 2014-04-19 kinaba: bool can_end_by(const vector<int>& X, int E) b9612fa18c 2014-04-19 kinaba: { b9612fa18c 2014-04-19 kinaba: for(int B=E;;) { b9612fa18c 2014-04-19 kinaba: if(run(B, X) == E) b9612fa18c 2014-04-19 kinaba: return true; b9612fa18c 2014-04-19 kinaba: b9612fa18c 2014-04-19 kinaba: if(B%2==0) b9612fa18c 2014-04-19 kinaba: B/=2; b9612fa18c 2014-04-19 kinaba: else b9612fa18c 2014-04-19 kinaba: break; b9612fa18c 2014-04-19 kinaba: } b9612fa18c 2014-04-19 kinaba: return false; b9612fa18c 2014-04-19 kinaba: } b9612fa18c 2014-04-19 kinaba: b9612fa18c 2014-04-19 kinaba: int run(int B, const vector<int>& X) b9612fa18c 2014-04-19 kinaba: { b9612fa18c 2014-04-19 kinaba: for(int x: X) b9612fa18c 2014-04-19 kinaba: B = (x==B ? B*2 : B); b9612fa18c 2014-04-19 kinaba: return B; b9612fa18c 2014-04-19 kinaba: } b9612fa18c 2014-04-19 kinaba: }; b9612fa18c 2014-04-19 kinaba: b9612fa18c 2014-04-19 kinaba: // BEGIN CUT HERE b9612fa18c 2014-04-19 kinaba: #include <ctime> b9612fa18c 2014-04-19 kinaba: double start_time; string timer() b9612fa18c 2014-04-19 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } b9612fa18c 2014-04-19 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) b9612fa18c 2014-04-19 kinaba: { os << "{ "; b9612fa18c 2014-04-19 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) b9612fa18c 2014-04-19 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } b9612fa18c 2014-04-19 kinaba: void verify_case(const int& Expected, const int& Received) { b9612fa18c 2014-04-19 kinaba: bool ok = (Expected == Received); b9612fa18c 2014-04-19 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; b9612fa18c 2014-04-19 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } b9612fa18c 2014-04-19 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); b9612fa18c 2014-04-19 kinaba: #define END verify_case(_, AmebaDiv1().count(X));} b9612fa18c 2014-04-19 kinaba: int main(){ b9612fa18c 2014-04-19 kinaba: b9612fa18c 2014-04-19 kinaba: CASE(0) b9612fa18c 2014-04-19 kinaba: int X_[] = {3,2,1}; b9612fa18c 2014-04-19 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); b9612fa18c 2014-04-19 kinaba: int _ = 2; b9612fa18c 2014-04-19 kinaba: END b9612fa18c 2014-04-19 kinaba: CASE(1) b9612fa18c 2014-04-19 kinaba: int X_[] = {2,2,2,2,2,2,4,2,2,2}; b9612fa18c 2014-04-19 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); b9612fa18c 2014-04-19 kinaba: int _ = 2; b9612fa18c 2014-04-19 kinaba: END b9612fa18c 2014-04-19 kinaba: CASE(2) b9612fa18c 2014-04-19 kinaba: int X_[] = {1,2,4,8,16,32,64,128,256,1024,2048}; b9612fa18c 2014-04-19 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); b9612fa18c 2014-04-19 kinaba: int _ = 11; b9612fa18c 2014-04-19 kinaba: END b9612fa18c 2014-04-19 kinaba: CASE(3) b9612fa18c 2014-04-19 kinaba: int X_[] = {854,250,934,1000,281,250,281,467,854,562,934,1000,854,500,562}; b9612fa18c 2014-04-19 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); b9612fa18c 2014-04-19 kinaba: int _ = 7; b9612fa18c 2014-04-19 kinaba: END b9612fa18c 2014-04-19 kinaba: /* b9612fa18c 2014-04-19 kinaba: CASE(4) b9612fa18c 2014-04-19 kinaba: int X_[] = ; b9612fa18c 2014-04-19 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); b9612fa18c 2014-04-19 kinaba: int _ = ; b9612fa18c 2014-04-19 kinaba: END b9612fa18c 2014-04-19 kinaba: CASE(5) b9612fa18c 2014-04-19 kinaba: int X_[] = ; b9612fa18c 2014-04-19 kinaba: vector <int> X(X_, X_+sizeof(X_)/sizeof(*X_)); b9612fa18c 2014-04-19 kinaba: int _ = ; b9612fa18c 2014-04-19 kinaba: END b9612fa18c 2014-04-19 kinaba: */ b9612fa18c 2014-04-19 kinaba: } b9612fa18c 2014-04-19 kinaba: // END CUT HERE