Artifact Content
Not logged in

Artifact 0a3d4549914a8f57e5a51a22f5314deca6670f2a


#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;

static const LL MODVAL = 1000000009; // must fit in 32-bits
LL ADD(LL x, LL y) { return (x+y)%MODVAL; }
LL SUB(LL x, LL y) { return (x-y+MODVAL)%MODVAL; }
LL MUL(LL x, LL y) { return (x*y)%MODVAL; }
LL POW(LL x, LL e) {
	LL v = 1;
	for(;e;x=MUL(x,x),e>>=1)
		if(e&1)
			v = MUL(v, x);
	return v;
}
LL DIV(LL x, LL y) { return MUL(x, POW(y, MODVAL-2)); }

class RabbitIncreasing { public:
	int getNumber(vector <int> leaving, int k) 
	{
		if( leaving.front() <= 1 )
			return 0;
		int li = 0;

		LL y[] = {1,0,0};
		LL p[] = {1,0,0};
		LL PP = (1LL << 55);
		for(int i=2; i<=k; ++i)
		{
			LL a=y[0], b=y[1], c=y[2];
			y[0]=y[2]=ADD(b,c); y[1]=a;
			LL pa=p[0], pb=p[1], pc=p[2];
			p[0]=p[2]=(pb+pc)%PP; p[1]=pa;
			if( li<leaving.size() && i==leaving[li] ) {
				++li;
				y[2] = 0;
				p[2] = 0;
				if( p[1]&1 ) {
					y[1]=DIV(SUB(y[1],1),2);
				} else {
					y[1]=DIV(y[1],2);
				}
				p[1]=p[1]/2;
				PP >>= 1;
			}
		}
		return ADD(y[0],ADD(y[1],y[2]));
	}
};

// 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(_, RabbitIncreasing().getNumber(leaving, k));}
int main(){

CASE(0)
	int leaving_[] = { 3 };
	  vector <int> leaving(leaving_, leaving_+sizeof(leaving_)/sizeof(*leaving_)); 
	int k = 3; 
	int _ = 1; 
END
CASE(1)
	int leaving_[] = { 5, 9 };
	  vector <int> leaving(leaving_, leaving_+sizeof(leaving_)/sizeof(*leaving_)); 
	int k = 10; 
	int _ = 6; 
END
CASE(2)
	int leaving_[] = { 5, 10, 15 };
	  vector <int> leaving(leaving_, leaving_+sizeof(leaving_)/sizeof(*leaving_)); 
	int k = 19; 
	int _ = 212; 
END
CASE(3)
	int leaving_[] = { 2 };
	  vector <int> leaving(leaving_, leaving_+sizeof(leaving_)/sizeof(*leaving_)); 
	int k = 10000000; 
	int _ = 0; 
END
CASE(4)
	int leaving_[] = { 195, 211, 227, 230, 260, 
  297, 346, 350, 403, 411, 
  428, 485, 594, 606, 876 }
;
	  vector <int> leaving(leaving_, leaving_+sizeof(leaving_)/sizeof(*leaving_)); 
	int k = 1000; 
	int _ = 975206486; 
END
CASE(5)
int leaving_[] = {2};
	  vector <int> leaving(leaving_, leaving_+sizeof(leaving_)/sizeof(*leaving_)); 
	int k = 1; 
	int _ = 1; 
END
CASE(5)
int leaving_[] = {2};
	  vector <int> leaving(leaving_, leaving_+sizeof(leaving_)/sizeof(*leaving_)); 
	int k = 2; 
	int _ = 0; 
END
CASE(5)
int leaving_[] = {1};
	  vector <int> leaving(leaving_, leaving_+sizeof(leaving_)/sizeof(*leaving_)); 
	int k = 1; 
	int _ = 0; 
END
CASE(6)
	int leaving_[] = {999};
	  vector <int> leaving(leaving_, leaving_+sizeof(leaving_)/sizeof(*leaving_)); 
	int k = 10000000; 
	int _ = 536491299; 
END
CASE(7)
	int leaving_[] = {
	100,200,300,400,500,600,700,800,900,1000,
	1100,1200,1300,1400,1500,1600,1700,1800,1900,2000,
	3100,3200,3300,3400,3500,3600,3700,3800,3900,31000,
	43100,43200,43300,43400,43500,43600,43700,43800,43900,431000,
	999100,999200,999300,999400,999500,999600,999700,999800,999900,9991000,
};
	  vector <int> leaving(leaving_, leaving_+sizeof(leaving_)/sizeof(*leaving_)); 
	int k = 10000000; 
	int _ = 260357174; 
END
}
// END CUT HERE