Artifact Content
Not logged in

Artifact be7ddcd5afb0c754c6de63475d75862a764198b2


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

class PuyoPuyo { public:
	int theCount(int L, int N) 
	{
		// A4 ::= U*
		// U  ::= x A3 x A3 x A3 x   (U::=U[0],  U[i]::=x A3 U[i+1],  U[L-1]::=x)

		vector<LL>           A4(N+1), A3(N+1);
		vector< vector<LL> > U(L, vector<LL>(N+1));

		A4[0] = A3[0] = U[L-1][1] = 1;
		for(int n=1; n<=N; ++n) {
			for(int k=L-2; k>=0; --k)
				for(int z=0; n-z-1>=1; z+=L)
					U[k][n] = (U[k][n] + A3[z]*U[k+1][n-z-1]) % MODVAL;
			for(int i=L; i<=n; i+=L)
				A4[n] = (A4[n] + 4*U[0][i]*A4[n-i]) % MODVAL;
			for(int i=L; i<=n; i+=L)
				A3[n] = (A3[n] + 3*U[0][i]*A3[n-i]) % MODVAL;
		}
		return int(A4[N]);
	}
};

// 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(_, PuyoPuyo().theCount(L, N));}
int main(){

CASE(0)
	int L = 2; 
	int N = 2; 
	int _ = 4; 
END
CASE(1)
	int L = 2; 
	int N = 4; 
	int _ = 28; 
END
CASE(2)
	int L = 2; 
	int N = 58; 
	int _ = 868294620; 
END
CASE(3)
	int L = 4; 
	int N = 84; 
	int _ = 621871151; 
END
CASE(4)
	int L = 5; 
	int N = 8; 
	int _ = 0; 
END
CASE(5)
	int L = 2; 
	int N = 1; 
	int _ = 0; 
END
CASE(6)
	int L = 2; 
	int N = 1000; 
	int _ = -1; 
END
CASE(7)
	int L = 2; 
	int N = 6; 
	int _ = 232; 
END
CASE(8)
	int L = 2; 
	int N = 8; 
	int _ = 2092; 
END
}
// END CUT HERE