File Annotation
Not logged in
b9612fa18c 2014-04-19        kinaba: #include <iostream>
b9612fa18c 2014-04-19        kinaba: #include <sstream>
b9612fa18c 2014-04-19        kinaba: #include <iomanip>
b9612fa18c 2014-04-19        kinaba: #include <vector>
b9612fa18c 2014-04-19        kinaba: #include <string>
b9612fa18c 2014-04-19        kinaba: #include <map>
b9612fa18c 2014-04-19        kinaba: #include <set>
b9612fa18c 2014-04-19        kinaba: #include <algorithm>
b9612fa18c 2014-04-19        kinaba: #include <numeric>
b9612fa18c 2014-04-19        kinaba: #include <iterator>
b9612fa18c 2014-04-19        kinaba: #include <functional>
b9612fa18c 2014-04-19        kinaba: #include <complex>
b9612fa18c 2014-04-19        kinaba: #include <queue>
b9612fa18c 2014-04-19        kinaba: #include <stack>
b9612fa18c 2014-04-19        kinaba: #include <cmath>
b9612fa18c 2014-04-19        kinaba: #include <cassert>
b9612fa18c 2014-04-19        kinaba: #include <tuple>
b9612fa18c 2014-04-19        kinaba: using namespace std;
b9612fa18c 2014-04-19        kinaba: typedef long long LL;
b9612fa18c 2014-04-19        kinaba: typedef complex<double> CMP;
b9612fa18c 2014-04-19        kinaba: 
b9612fa18c 2014-04-19        kinaba: static const unsigned MODVAL = 1000000007;
b9612fa18c 2014-04-19        kinaba: struct mint
b9612fa18c 2014-04-19        kinaba: {
b9612fa18c 2014-04-19        kinaba: 	unsigned val;
b9612fa18c 2014-04-19        kinaba: 	mint():val(0){}
b9612fa18c 2014-04-19        kinaba: 	mint(int      x):val(x%MODVAL) {}
b9612fa18c 2014-04-19        kinaba: 	mint(unsigned x):val(x%MODVAL) {}
b9612fa18c 2014-04-19        kinaba: 	mint(LL       x):val(x%MODVAL) {}
b9612fa18c 2014-04-19        kinaba: };
b9612fa18c 2014-04-19        kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
b9612fa18c 2014-04-19        kinaba: mint operator+(mint x, mint y) { return x+=y; }
b9612fa18c 2014-04-19        kinaba: 
b9612fa18c 2014-04-19        kinaba: class AlternativePiles { public:
b9612fa18c 2014-04-19        kinaba: 	int count(string C, int M)
b9612fa18c 2014-04-19        kinaba: 	{
b9612fa18c 2014-04-19        kinaba: 		vector<mint> dp((M+1)*M);
b9612fa18c 2014-04-19        kinaba: 		dp[0] = 1;
b9612fa18c 2014-04-19        kinaba: 
b9612fa18c 2014-04-19        kinaba: 		for(char c : C)
b9612fa18c 2014-04-19        kinaba: 		{
b9612fa18c 2014-04-19        kinaba: 			vector<mint> dp2((M+1)*M);
b9612fa18c 2014-04-19        kinaba: 			for(int m=0; m<=M; ++m)
b9612fa18c 2014-04-19        kinaba: 			for(int r=0; r<M; ++r) {
b9612fa18c 2014-04-19        kinaba: 				int mr = m*M+r;
b9612fa18c 2014-04-19        kinaba: 				if((c=='R' || c=='W') && m+1<=M)
b9612fa18c 2014-04-19        kinaba: 					dp2[(m+1)*M+(r+1)%M] += dp[mr];
b9612fa18c 2014-04-19        kinaba: 				if((c=='G' || c=='W') && m-1>=0)
b9612fa18c 2014-04-19        kinaba: 					dp2[(m-1)*M+r] += dp[mr];
b9612fa18c 2014-04-19        kinaba: 				if(c=='B' || c=='W')
b9612fa18c 2014-04-19        kinaba: 					dp2[m*M+r] += dp[mr];
b9612fa18c 2014-04-19        kinaba: 			}
b9612fa18c 2014-04-19        kinaba: 			dp.swap(dp2);
b9612fa18c 2014-04-19        kinaba: 		}
b9612fa18c 2014-04-19        kinaba: 		return dp[0].val;
b9612fa18c 2014-04-19        kinaba: 	}
b9612fa18c 2014-04-19        kinaba: };
b9612fa18c 2014-04-19        kinaba: 
b9612fa18c 2014-04-19        kinaba: // BEGIN CUT HERE
b9612fa18c 2014-04-19        kinaba: #include <ctime>
b9612fa18c 2014-04-19        kinaba: double start_time; string timer()
b9612fa18c 2014-04-19        kinaba:  { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
b9612fa18c 2014-04-19        kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
b9612fa18c 2014-04-19        kinaba:  { os << "{ ";
b9612fa18c 2014-04-19        kinaba:    for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
b9612fa18c 2014-04-19        kinaba:    os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
b9612fa18c 2014-04-19        kinaba: void verify_case(const int& Expected, const int& Received) {
b9612fa18c 2014-04-19        kinaba:  bool ok = (Expected == Received);
b9612fa18c 2014-04-19        kinaba:  if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
b9612fa18c 2014-04-19        kinaba:  cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
b9612fa18c 2014-04-19        kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
b9612fa18c 2014-04-19        kinaba: #define END	 verify_case(_, AlternativePiles().count(C, M));}
b9612fa18c 2014-04-19        kinaba: int main(){
b9612fa18c 2014-04-19        kinaba: 
b9612fa18c 2014-04-19        kinaba: CASE(0)
b9612fa18c 2014-04-19        kinaba: 	string C = "WRGWWRGW";
b9612fa18c 2014-04-19        kinaba: 	int M = 2;
b9612fa18c 2014-04-19        kinaba: 	int _ = 3;
b9612fa18c 2014-04-19        kinaba: END
b9612fa18c 2014-04-19        kinaba: CASE(1)
b9612fa18c 2014-04-19        kinaba: 	string C = "RRGG";
b9612fa18c 2014-04-19        kinaba: 	int M = 1;
b9612fa18c 2014-04-19        kinaba: 	int _ = 0;
b9612fa18c 2014-04-19        kinaba: END
b9612fa18c 2014-04-19        kinaba: CASE(2)
b9612fa18c 2014-04-19        kinaba: 	string C = "BBBB";
b9612fa18c 2014-04-19        kinaba: 	int M = 5;
b9612fa18c 2014-04-19        kinaba: 	int _ = 1;
b9612fa18c 2014-04-19        kinaba: END
b9612fa18c 2014-04-19        kinaba: CASE(3)
b9612fa18c 2014-04-19        kinaba: 	string C = "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW";
b9612fa18c 2014-04-19        kinaba: 	int M = 50;
b9612fa18c 2014-04-19        kinaba: 	int _ = 265470435;
b9612fa18c 2014-04-19        kinaba: END
b9612fa18c 2014-04-19        kinaba: CASE(4)
b9612fa18c 2014-04-19        kinaba: 	string C = "WRWRGWWGWWWRWBWRWGWWRWBWWRGWBWGRGWWGWGRWGRWBRWBW";
b9612fa18c 2014-04-19        kinaba: 	int M = 7;
b9612fa18c 2014-04-19        kinaba: 	int _ = 7400348;
b9612fa18c 2014-04-19        kinaba: END
b9612fa18c 2014-04-19        kinaba: /*
b9612fa18c 2014-04-19        kinaba: CASE(6)
b9612fa18c 2014-04-19        kinaba: 	string C = ;
b9612fa18c 2014-04-19        kinaba: 	int M = ;
b9612fa18c 2014-04-19        kinaba: 	int _ = ;
b9612fa18c 2014-04-19        kinaba: END
b9612fa18c 2014-04-19        kinaba: */
b9612fa18c 2014-04-19        kinaba: }
b9612fa18c 2014-04-19        kinaba: // END CUT HERE