Artifact Content
Not logged in

Artifact 561cc23e487a1233d6c3114885493c1c07fce837


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class AfraidOfEven { public:
	vector <int> restoreProgression(vector <int> seq) 
	{
		LL a = seq[0];
		LL b = seq[1];
		for(LL aa=a; aa<=0x7fffffff; aa*=2)
		for(LL bb=b; bb<=0x7fffffff; bb*=2)
			if( possible(seq,aa,bb) )
				return seq;
		assert(false);
	}
	bool possible(vector<int>& seq, LL a, LL b)
	{
		LL d = b-a;
		vector<LL> q(seq.size());
		q[0] = a;
		q[1] = b;
		for(int i=2; i<seq.size(); ++i)
		{
			q[i] = q[i-1] + d;
			if( q[i] <= 0 )
				return false;
			if( q[i] % seq[i] != 0 )
				return false;
			LL f = q[i] / seq[i];
			if( f & (f-1) )
				return false;
		}
		for(int i=0; i<seq.size(); ++i)
			seq[i] = int(q[i]);
		return true;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const vector <int>& Expected, const vector <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(_, AfraidOfEven().restoreProgression(seq));}
int main(){

CASE(0)
	int seq_[] = {1, 1, 3, 1, 5};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int __[] = {1, 2, 3, 4, 5 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	int seq_[] = {9, 7, 5, 3, 1};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int __[] = {9, 7, 5, 3, 1 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(2)
	int seq_[] = {999, 999, 999, 999};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int __[] = {999, 999, 999, 999 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(3)
	int seq_[] = {7, 47, 5, 113, 73, 179, 53};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int __[] = {14, 47, 80, 113, 146, 179, 212 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(4)
	int seq_[] = {749, 999, 125, 1};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int __[] = {1498, 999, 500, 1 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(5)
int seq_[] = {3,7,1,9};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	  int __[] = {6,7,8,9};
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
/*
CASE(6)
	int seq_[] = ;
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int __[] = ;
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
*/
}
// END CUT HERE