Artifact 3d778b85bf6f47a511b5c595e725415dbfc87fda
#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 YetAnotherORProblem { public:
map<vector<LL>, int> memo;
int countSequences(const vector<LL>& R)
{
if( count(R.begin(),R.end(),0) == R.size() )
return 1;
if( memo.count(R) )
return memo[R];
vector<LL> RR;
for(int i=0; i<R.size(); ++i)
RR.push_back(R[i]/2);
int total = countSequences(RR);
for(int i=0; i<R.size(); ++i)
if( R[i] )
{
if( (R[i]&1) == 0 ) RR[i]--;
total = (total + countSequences(RR)) % 1000000009;
if( (R[i]&1) == 0 ) RR[i]++;
}
return memo[R] = total;
}
};
// 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 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(_, YetAnotherORProblem().countSequences(R));}
int main(){
CASE(0)
long R_[] = {3,5};
vector<long long> R(R_, R_+sizeof(R_)/sizeof(*R_));
int _ = 15;
END
CASE(1)
long R_[] = {3,3,3};
vector<long long> R(R_, R_+sizeof(R_)/sizeof(*R_));
int _ = 16;
END
CASE(2)
long R_[] = {1,128};
vector<long long> R(R_, R_+sizeof(R_)/sizeof(*R_));
int _ = 194;
END
CASE(3)
long R_[] = {26,74,25,30};
vector<long long> R(R_, R_+sizeof(R_)/sizeof(*R_));
int _ = 8409;
END
CASE(4)
long R_[] = {1000000000,1000000000};
vector<long long> R(R_, R_+sizeof(R_)/sizeof(*R_));
int _ = 420352509;
END
CASE(5)
long long R_[] = {1000000000000000000LL,1000000000000000000LL,1000000000000000000LL,1000000000000000000LL,1000000000000000000LL,1000000000000000000LL,1000000000000000000LL,1000000000000000000LL,1000000000000000000LL,1000000000000000000LL};
vector<long long> R(R_, R_+sizeof(R_)/sizeof(*R_));
int _ = -1;
END
CASE(6)
long long R_[] = {1, 1};
vector<long long> R(R_, R_+sizeof(R_)/sizeof(*R_));
int _ = 3;
END
CASE(6)
long long R_[] = {0xfffffffffffffffLL, 0xfffffffffffffffLL, 0xfffffffffffffffLL, 0xfffffffffffffffLL, 0xfffffffffffffffLL, 0xfffffffffffffffLL, 0xfffffffffffffffLL, 0xfffffffffffffffLL, 0xfffffffffffffffLL, 0xfffffffffffffffLL, };
vector<long long> R(R_, R_+sizeof(R_)/sizeof(*R_));
int _ = 3;
END
}
// END CUT HERE