File Annotation
Not logged in
2adfb7dfc0 2013-04-20        kinaba: #include <iostream>
2adfb7dfc0 2013-04-20        kinaba: #include <sstream>
2adfb7dfc0 2013-04-20        kinaba: #include <iomanip>
2adfb7dfc0 2013-04-20        kinaba: #include <vector>
2adfb7dfc0 2013-04-20        kinaba: #include <string>
2adfb7dfc0 2013-04-20        kinaba: #include <map>
2adfb7dfc0 2013-04-20        kinaba: #include <set>
2adfb7dfc0 2013-04-20        kinaba: #include <algorithm>
2adfb7dfc0 2013-04-20        kinaba: #include <numeric>
2adfb7dfc0 2013-04-20        kinaba: #include <iterator>
2adfb7dfc0 2013-04-20        kinaba: #include <functional>
2adfb7dfc0 2013-04-20        kinaba: #include <complex>
2adfb7dfc0 2013-04-20        kinaba: #include <queue>
2adfb7dfc0 2013-04-20        kinaba: #include <stack>
2adfb7dfc0 2013-04-20        kinaba: #include <cmath>
2adfb7dfc0 2013-04-20        kinaba: #include <cassert>
2adfb7dfc0 2013-04-20        kinaba: using namespace std;
2adfb7dfc0 2013-04-20        kinaba: typedef long long LL;
2adfb7dfc0 2013-04-20        kinaba: typedef long double LD;
2adfb7dfc0 2013-04-20        kinaba: typedef complex<LD> CMP;
2adfb7dfc0 2013-04-20        kinaba: 
2adfb7dfc0 2013-04-20        kinaba: static const unsigned MODVAL = 1000000009;
2adfb7dfc0 2013-04-20        kinaba: struct mint
2adfb7dfc0 2013-04-20        kinaba: {
2adfb7dfc0 2013-04-20        kinaba: 	unsigned val;
2adfb7dfc0 2013-04-20        kinaba: 	mint():val(0){}
2adfb7dfc0 2013-04-20        kinaba: 	mint(int      x):val(x%MODVAL) {}
2adfb7dfc0 2013-04-20        kinaba: 	mint(unsigned x):val(x%MODVAL) {}
2adfb7dfc0 2013-04-20        kinaba: 	mint(LL       x):val(x%MODVAL) {}
2adfb7dfc0 2013-04-20        kinaba: };
2adfb7dfc0 2013-04-20        kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
2adfb7dfc0 2013-04-20        kinaba: mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; }
2adfb7dfc0 2013-04-20        kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
2adfb7dfc0 2013-04-20        kinaba: mint operator+(mint x, mint y) { return x+=y; }
2adfb7dfc0 2013-04-20        kinaba: mint operator-(mint x, mint y) { return x-=y; }
2adfb7dfc0 2013-04-20        kinaba: mint operator*(mint x, mint y) { return x*=y; }
2adfb7dfc0 2013-04-20        kinaba: 
2adfb7dfc0 2013-04-20        kinaba: template<typename T>
2adfb7dfc0 2013-04-20        kinaba: struct DP4x
2adfb7dfc0 2013-04-20        kinaba: {
2adfb7dfc0 2013-04-20        kinaba: 	int N1, N2, N3, N4;
2adfb7dfc0 2013-04-20        kinaba: 	vector<T> data;
2adfb7dfc0 2013-04-20        kinaba: 	DP4x(int, int N2, int N3, int N4, const T& t = T())
2adfb7dfc0 2013-04-20        kinaba: 		: N1(2), N2(N2), N3(N3), N4(N4), data(N1*N2*N3*N4, t) { assert(data.size()*sizeof(T)<(1<<26)); }
2adfb7dfc0 2013-04-20        kinaba: 	T& operator()(int i1, int i2, int i3, int i4)
2adfb7dfc0 2013-04-20        kinaba: 		{ i1&=1; return data[ (((i1*N2)+i2)*N3+i3)*N4+i4 ]; }
2adfb7dfc0 2013-04-20        kinaba: 	void swap(DP4x& rhs)
2adfb7dfc0 2013-04-20        kinaba: 		{ data.swap(rhs.data); }
2adfb7dfc0 2013-04-20        kinaba: };
2adfb7dfc0 2013-04-20        kinaba: 
2adfb7dfc0 2013-04-20        kinaba: class TheExperiment { public:
2adfb7dfc0 2013-04-20        kinaba: 	int countPlacements(vector <string> intensity, int M, int L, int A, int B)
2adfb7dfc0 2013-04-20        kinaba: 	{
2adfb7dfc0 2013-04-20        kinaba: 		string S = accumulate(intensity.begin(), intensity.end(), string());
2adfb7dfc0 2013-04-20        kinaba: 		int N = S.size();
2adfb7dfc0 2013-04-20        kinaba: 
2adfb7dfc0 2013-04-20        kinaba: 		vector<int> range_L, range_R; // [L,R)
2adfb7dfc0 2013-04-20        kinaba: 		{
2adfb7dfc0 2013-04-20        kinaba: 			vector<int> PS(N+1, 0);
2adfb7dfc0 2013-04-20        kinaba: 			for(int i=0; i<N; ++i)
2adfb7dfc0 2013-04-20        kinaba: 				PS[i+1] = PS[i] + (S[i]-'0');
2adfb7dfc0 2013-04-20        kinaba: 			for(int i=0; i<N; ++i)
2adfb7dfc0 2013-04-20        kinaba: 			{
2adfb7dfc0 2013-04-20        kinaba: 				int LL = PS[i]+A;
2adfb7dfc0 2013-04-20        kinaba: 				int RR = PS[i]+B+1;
2adfb7dfc0 2013-04-20        kinaba: 				range_L.push_back(lower_bound(PS.begin(), PS.end(), LL) - PS.begin());
2adfb7dfc0 2013-04-20        kinaba: 				range_R.push_back(lower_bound(PS.begin(), PS.end(), RR) - PS.begin());
2adfb7dfc0 2013-04-20        kinaba: 				//cerr<<i<<" ["<<range_L.back()<<"-"<<range_R.back()<<")"<<" "<<LL<<","<<RR<<endl;
2adfb7dfc0 2013-04-20        kinaba: 			}
2adfb7dfc0 2013-04-20        kinaba: 		}
2adfb7dfc0 2013-04-20        kinaba: 
2adfb7dfc0 2013-04-20        kinaba: 		DP4x<mint> dp(M+1, N+1, M, 2);
2adfb7dfc0 2013-04-20        kinaba: 		dp(0, 0, 0, 0) = 1;
2adfb7dfc0 2013-04-20        kinaba: 		for(int i=0; i<M; ++i)
2adfb7dfc0 2013-04-20        kinaba: 		{
2adfb7dfc0 2013-04-20        kinaba: 			// Clear
2adfb7dfc0 2013-04-20        kinaba: 			for(int x=0; x<=N; ++x)
2adfb7dfc0 2013-04-20        kinaba: 			for(int rank=0; rank<M; ++rank) {
2adfb7dfc0 2013-04-20        kinaba: 			for(int hami=0; hami<2; ++hami) {
2adfb7dfc0 2013-04-20        kinaba: 				if(dp(i,x,rank,hami).val)
2adfb7dfc0 2013-04-20        kinaba: 				cerr<<i<<" "<<x<<" "<<rank<<" "<<hami<<" : "<< dp(i,x,rank,hami).val<<endl;
2adfb7dfc0 2013-04-20        kinaba: 				dp(i+1, x, rank, hami) = 0;
2adfb7dfc0 2013-04-20        kinaba: 			}
2adfb7dfc0 2013-04-20        kinaba: 
2adfb7dfc0 2013-04-20        kinaba: 			// DP
2adfb7dfc0 2013-04-20        kinaba: 			for(int x=0; x<N; ++x)
2adfb7dfc0 2013-04-20        kinaba: 			for(int rank=0; rank<=i; ++rank)
2adfb7dfc0 2013-04-20        kinaba: 			for(int hami=0; hami<2; ++hami)
2adfb7dfc0 2013-04-20        kinaba: 			{
2adfb7dfc0 2013-04-20        kinaba: 				mint v = dp(i,x,rank,hami);
2adfb7dfc0 2013-04-20        kinaba: 				if(v.val != 0)
2adfb7dfc0 2013-04-20        kinaba: 					for(int y=range_L[x]; y<range_R[x]; ++y)
2adfb7dfc0 2013-04-20        kinaba: 					{
2adfb7dfc0 2013-04-20        kinaba: 						if(y-x < L) {
2adfb7dfc0 2013-04-20        kinaba: 							if(hami) {
2adfb7dfc0 2013-04-20        kinaba: 								for(int r=0; r<=rank; ++r)
2adfb7dfc0 2013-04-20        kinaba: 									dp(i+1, y, a) += v;
2adfb7dfc0 2013-04-20        kinaba: 							} else {
2adfb7dfc0 2013-04-20        kinaba: 							}
2adfb7dfc0 2013-04-20        kinaba: 						} else if(y-x == L) {
2adfb7dfc0 2013-04-20        kinaba: 							if(hami)
2adfb7dfc0 2013-04-20        kinaba: 								dp(i+1, y, i, 0) += v * (rank+1);
2adfb7dfc0 2013-04-20        kinaba: 							else
2adfb7dfc0 2013-04-20        kinaba: 								dp(i+1, y, i, 0) += v * (rank+1);
2adfb7dfc0 2013-04-20        kinaba: 						} else {
2adfb7dfc0 2013-04-20        kinaba: 							break;
2adfb7dfc0 2013-04-20        kinaba: 						}
2adfb7dfc0 2013-04-20        kinaba: 					}
2adfb7dfc0 2013-04-20        kinaba: 			}
2adfb7dfc0 2013-04-20        kinaba: 		}
2adfb7dfc0 2013-04-20        kinaba: 		mint acc = 0;
2adfb7dfc0 2013-04-20        kinaba: 		for(int rank=0; rank<M; ++rank)
2adfb7dfc0 2013-04-20        kinaba: 			acc += dp(M, N, rank, 0);
2adfb7dfc0 2013-04-20        kinaba: 		return acc.val;
2adfb7dfc0 2013-04-20        kinaba: 	}
2adfb7dfc0 2013-04-20        kinaba: };
2adfb7dfc0 2013-04-20        kinaba: 
2adfb7dfc0 2013-04-20        kinaba: // BEGIN CUT HERE
2adfb7dfc0 2013-04-20        kinaba: #include <ctime>
2adfb7dfc0 2013-04-20        kinaba: double start_time; string timer()
2adfb7dfc0 2013-04-20        kinaba:  { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
2adfb7dfc0 2013-04-20        kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
2adfb7dfc0 2013-04-20        kinaba:  { os << "{ ";
2adfb7dfc0 2013-04-20        kinaba:    for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
2adfb7dfc0 2013-04-20        kinaba:    os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
2adfb7dfc0 2013-04-20        kinaba: void verify_case(const int& Expected, const int& Received) {
2adfb7dfc0 2013-04-20        kinaba:  bool ok = (Expected == Received);
2adfb7dfc0 2013-04-20        kinaba:  if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
2adfb7dfc0 2013-04-20        kinaba:  cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
2adfb7dfc0 2013-04-20        kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
2adfb7dfc0 2013-04-20        kinaba: #define END	 verify_case(_, TheExperiment().countPlacements(intensity, M, L, A, B));}
2adfb7dfc0 2013-04-20        kinaba: int main(){
2adfb7dfc0 2013-04-20        kinaba: 
2adfb7dfc0 2013-04-20        kinaba: CASE(0)
2adfb7dfc0 2013-04-20        kinaba: 	string intensity_[] = {"341156"};
2adfb7dfc0 2013-04-20        kinaba: 	  vector <string> intensity(intensity_, intensity_+sizeof(intensity_)/sizeof(*intensity_));
2adfb7dfc0 2013-04-20        kinaba: 	int M = 3;
2adfb7dfc0 2013-04-20        kinaba: 	int L = 3;
2adfb7dfc0 2013-04-20        kinaba: 	int A = 6;
2adfb7dfc0 2013-04-20        kinaba: 	int B = 10;
2adfb7dfc0 2013-04-20        kinaba: 	int _ = 2;
2adfb7dfc0 2013-04-20        kinaba: END
2adfb7dfc0 2013-04-20        kinaba: CASE(1)
2adfb7dfc0 2013-04-20        kinaba: 	string intensity_[] = {"999112999"};
2adfb7dfc0 2013-04-20        kinaba: 	  vector <string> intensity(intensity_, intensity_+sizeof(intensity_)/sizeof(*intensity_));
2adfb7dfc0 2013-04-20        kinaba: 	int M = 2;
2adfb7dfc0 2013-04-20        kinaba: 	int L = 4;
2adfb7dfc0 2013-04-20        kinaba: 	int A = 21;
2adfb7dfc0 2013-04-20        kinaba: 	int B = 30;
2adfb7dfc0 2013-04-20        kinaba: 	int _ = 2;
2adfb7dfc0 2013-04-20        kinaba: END
2adfb7dfc0 2013-04-20        kinaba: CASE(2)
2adfb7dfc0 2013-04-20        kinaba: 	string intensity_[] = {"111"};
2adfb7dfc0 2013-04-20        kinaba: 	  vector <string> intensity(intensity_, intensity_+sizeof(intensity_)/sizeof(*intensity_));
2adfb7dfc0 2013-04-20        kinaba: 	int M = 2;
2adfb7dfc0 2013-04-20        kinaba: 	int L = 2;
2adfb7dfc0 2013-04-20        kinaba: 	int A = 2;
2adfb7dfc0 2013-04-20        kinaba: 	int B = 3;
2adfb7dfc0 2013-04-20        kinaba: 	int _ = 0;
2adfb7dfc0 2013-04-20        kinaba: END
2adfb7dfc0 2013-04-20        kinaba: CASE(3)
2adfb7dfc0 2013-04-20        kinaba: 	string intensity_[] = {"59059", "110", "1132230231"};
2adfb7dfc0 2013-04-20        kinaba: 	  vector <string> intensity(intensity_, intensity_+sizeof(intensity_)/sizeof(*intensity_));
2adfb7dfc0 2013-04-20        kinaba: 	int M = 1;
2adfb7dfc0 2013-04-20        kinaba: 	int L = 5;
2adfb7dfc0 2013-04-20        kinaba: 	int A = 10;
2adfb7dfc0 2013-04-20        kinaba: 	int B = 20;
2adfb7dfc0 2013-04-20        kinaba: 	int _ = 6;
2adfb7dfc0 2013-04-20        kinaba: END
2adfb7dfc0 2013-04-20        kinaba: CASE(4)
2adfb7dfc0 2013-04-20        kinaba: 	string intensity_[] = {"111111111111111111111111", "111111111111111111111111111", "11111111111111111111111"};
2adfb7dfc0 2013-04-20        kinaba: 	  vector <string> intensity(intensity_, intensity_+sizeof(intensity_)/sizeof(*intensity_));
2adfb7dfc0 2013-04-20        kinaba: 	int M = 12;
2adfb7dfc0 2013-04-20        kinaba: 	int L = 8;
2adfb7dfc0 2013-04-20        kinaba: 	int A = 4;
2adfb7dfc0 2013-04-20        kinaba: 	int B = 2700;
2adfb7dfc0 2013-04-20        kinaba: 	int _ = 418629948;
2adfb7dfc0 2013-04-20        kinaba: END
2adfb7dfc0 2013-04-20        kinaba: /*
2adfb7dfc0 2013-04-20        kinaba: CASE(5)
2adfb7dfc0 2013-04-20        kinaba: 	string intensity_[] = ;
2adfb7dfc0 2013-04-20        kinaba: 	  vector <string> intensity(intensity_, intensity_+sizeof(intensity_)/sizeof(*intensity_));
2adfb7dfc0 2013-04-20        kinaba: 	int M = ;
2adfb7dfc0 2013-04-20        kinaba: 	int L = ;
2adfb7dfc0 2013-04-20        kinaba: 	int A = ;
2adfb7dfc0 2013-04-20        kinaba: 	int B = ;
2adfb7dfc0 2013-04-20        kinaba: 	int _ = ;
2adfb7dfc0 2013-04-20        kinaba: END
2adfb7dfc0 2013-04-20        kinaba: CASE(6)
2adfb7dfc0 2013-04-20        kinaba: 	string intensity_[] = ;
2adfb7dfc0 2013-04-20        kinaba: 	  vector <string> intensity(intensity_, intensity_+sizeof(intensity_)/sizeof(*intensity_));
2adfb7dfc0 2013-04-20        kinaba: 	int M = ;
2adfb7dfc0 2013-04-20        kinaba: 	int L = ;
2adfb7dfc0 2013-04-20        kinaba: 	int A = ;
2adfb7dfc0 2013-04-20        kinaba: 	int B = ;
2adfb7dfc0 2013-04-20        kinaba: 	int _ = ;
2adfb7dfc0 2013-04-20        kinaba: END
2adfb7dfc0 2013-04-20        kinaba: */
2adfb7dfc0 2013-04-20        kinaba: }
2adfb7dfc0 2013-04-20        kinaba: // END CUT HERE