Artifact Content
Not logged in

Artifact 7e42d41150443f381dda57c20829a951779a191a


#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 int MODVAL = 1000000007;
typedef pair<pair<LL,LL>,LL> state;

class RabbitPuzzle { public:
	int theCount(vector<long long> rabbits, vector<long long> nests, int K) 
	{
		state s(make_pair(rabbits[0],rabbits[1]), rabbits[2]);
		state g(make_pair(nests[0],nests[1]), nests[2]);

		map<state,int> ms, mg;
		calc(s, K/2, ms);
		calc(g, (K+1)/2, mg);

		int result = 0;
		for(map<state,int>::iterator it=ms.begin(); it!=ms.end(); ++it) {
			map<state,int>::iterator jt = mg.find(it->first);
			if( jt != mg.end() )
				result = (result + LL(it->second)*jt->second)%MODVAL;
		}
		return result;
	}

	void calc(const state& s, int n, map<state,int>& m)
	{
		if( n == 0 )
			(m[s] += 1) %= MODVAL;
		else {
			LL a = s.first.first;
			LL b = s.first.second;
			LL c = s.second;
			if( 2*b-a < c ) calc(state(make_pair(b,2*b-a),c), n-1, m);
			calc(state(make_pair(2*a-b,a),c), n-1, m);
			calc(state(make_pair(a,c),2*c-b), n-1, m);
			if( a < 2*b-c ) calc(state(make_pair(a,2*b-c),b), n-1, m);
		}
	}
};

// 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(_, RabbitPuzzle().theCount(rabbits, nests, K));}
int main(){

CASE(0)
	long rabbits_[] = {0, 5, 8};
	  vector<long long> rabbits(rabbits_, rabbits_+sizeof(rabbits_)/sizeof(*rabbits_)); 
	long nests_[] = {0, 8, 11};
	  vector<long long> nests(nests_, nests_+sizeof(nests_)/sizeof(*nests_)); 
	int K = 1; 
	int _ = 1; 
END
CASE(1)
	long rabbits_[] = {0, 5, 8};
	  vector<long long> rabbits(rabbits_, rabbits_+sizeof(rabbits_)/sizeof(*rabbits_)); 
	long nests_[] = {0, 8, 11};
	  vector<long long> nests(nests_, nests_+sizeof(nests_)/sizeof(*nests_)); 
	int K = 3; 
	int _ = 5; 
END
CASE(2)
	long rabbits_[] = {0, 5, 8};
	  vector<long long> rabbits(rabbits_, rabbits_+sizeof(rabbits_)/sizeof(*rabbits_)); 
	long nests_[] = {0, 8, 11};
	  vector<long long> nests(nests_, nests_+sizeof(nests_)/sizeof(*nests_)); 
	int K = 2; 
	int _ = 0; 
END
CASE(3)
	long rabbits_[] = {5, 8, 58};
	  vector<long long> rabbits(rabbits_, rabbits_+sizeof(rabbits_)/sizeof(*rabbits_)); 
	long nests_[] = {13, 22, 64};
	  vector<long long> nests(nests_, nests_+sizeof(nests_)/sizeof(*nests_)); 
	int K = 58; 
	int _ = 0; 
END
CASE(4)
	long rabbits_[] = {0, 1, 2};
	  vector<long long> rabbits(rabbits_, rabbits_+sizeof(rabbits_)/sizeof(*rabbits_)); 
	long nests_[] = {1, 2, 3};
	  vector<long long> nests(nests_, nests_+sizeof(nests_)/sizeof(*nests_)); 
	int K = 100; 
	int _ = 0; 
END
CASE(5)
	long rabbits_[] = {5, 8, 58};
	  vector<long long> rabbits(rabbits_, rabbits_+sizeof(rabbits_)/sizeof(*rabbits_)); 
	long nests_[] = {20, 26, 61};
	  vector<long long> nests(nests_, nests_+sizeof(nests_)/sizeof(*nests_)); 
	int K = 58; 
	int _ = 537851168; 
END
CASE(6)
	long rabbits_[] = {67, 281, 2348};
	  vector<long long> rabbits(rabbits_, rabbits_+sizeof(rabbits_)/sizeof(*rabbits_)); 
	long nests_[] = {235, 1394, 3293};
	  vector<long long> nests(nests_, nests_+sizeof(nests_)/sizeof(*nests_)); 
	int K = 83; 
	int _ = 167142023; 
END
CASE(7)
	long rabbits_[] = {-1000000000000000000, 999999999999999998, 999999999999999999};
	  vector<long long> rabbits(rabbits_, rabbits_+sizeof(rabbits_)/sizeof(*rabbits_)); 
	long nests_[] = {-1000000000000000000, 999999999999999999, 1000000000000000000};
	  vector<long long> nests(nests_, nests_+sizeof(nests_)/sizeof(*nests_)); 
	int K = 5; 
	int _ = 29; 
END

}
// END CUT HERE