Artifact Content
Not logged in

Artifact 3680215ae4f12899056694d2a64d0b272945fadf


#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; // must be prime for op/
struct mint
{
	int val;
	mint():val(0){}
	mint(int    x):val(x%MODVAL) {}
	mint(size_t x):val(x%MODVAL) {}
	mint(LL     x):val(x%MODVAL) {}
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; }
mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); }
mint operator+(mint x, mint y) { return x+=y; }
mint operator-(mint x, mint y) { return x-=y; }
mint operator*(mint x, mint y) { return x*=y; }
mint operator/(mint x, mint y) { return x/=y; }
vector<mint> FAC_(1,1);
mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*FAC_.size() ); return FAC_[n]; }
mint C(LL n, LL k) { return k<0 || n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }

template<typename T>
struct DP4
{
	int N1, N2, N3, N4;
	vector<T> data;
	DP4(int N1, int N2, int N3, int N4, const T& t = T())
		: N1(N1), N2(N2), N3(N3), N4(N4), data(N1*N2*N3*N4, t) { assert(data.size()*sizeof(T)<(1<<26)); }
	T& operator()(int i1, int i2, int i3, int i4)
		{ return data[ (((i1*N2)+i2)*N3+i3)*N4+i4 ]; }
	void swap(DP4& rhs)
		{ data.swap(rhs.data); }
};

class SRMIntermissionPhase { public:
	int countWays(vector <int> points, vector <string> description)
	{
		const int TOTAL = accumulate(points.begin(), points.end(), 0);

		DP4<mint> patnum(2,2,2,TOTAL+1);
		int a[3];
		for(a[0]=0; a[0]<2; ++a[0])
		for(a[1]=0; a[1]<2; ++a[1])
		for(a[2]=0; a[2]<2; ++a[2])
		{
			patnum(a[0],a[1],a[2],0) = 1;
			for(int i=0; i<3; ++i) if(a[i]) {
				for(int p=1; p<=TOTAL; ++p)
					patnum(a[0],a[1],a[2],p) += patnum(a[0],a[1],a[2],p-1);
				for(int p=TOTAL; p>=points[i]+1; --p)
					patnum(a[0],a[1],a[2],p) = patnum(a[0],a[1],a[2],p-1) - patnum(a[0],a[1],a[2],p-points[i]-1);
				for(int p=points[i]; p>=0; --p)
					patnum(a[0],a[1],a[2],p) = p>0 ? patnum(a[0],a[1],a[2],p-1) : 0;
			}
		}

		vector<mint> dp(TOTAL+2);
		dp[0] = 1; // -1
		for(int i=description.size()-1; i>=0; --i)
		{
			partial_sum(dp.begin(), dp.end(), dp.begin());
			for(int s=TOTAL; s>=0; --s)
				dp[s+1] = dp[s] * patnum(
					description[i][0]=='Y',
					description[i][1]=='Y',
					description[i][2]=='Y',
					s
				);
			dp[0] = 0;
		}
		return accumulate(dp.begin()+1, dp.end(), mint(0)).val;
	}
};

// 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(_, SRMIntermissionPhase().countWays(points, description));}
int main(){

CASE(4)
int points_[] = {1,2,3};
	  vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); 
	  string description_[] = {"YNN","NNN"};
	  vector <string> description(description_, description_+sizeof(description_)/sizeof(*description_)); 
	int _ = 1; 
END
CASE(0)
	int points_[] = {25000, 50000, 100000};
	  vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); 
	string description_[] = {"YNN",
 "NNN"};
	  vector <string> description(description_, description_+sizeof(description_)/sizeof(*description_)); 
	int _ = 25000; 
END
CASE(1)
	int points_[] = {30000, 60000, 90000};
	  vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); 
	string description_[] = {"NYN",
 "NYN"};
	  vector <string> description(description_, description_+sizeof(description_)/sizeof(*description_)); 
	int _ = 799969993; 
END
CASE(2)
	int points_[] = {25000, 45000, 110000};
	  vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); 
	string description_[] = {"NNN",
 "YYY"};
	  vector <string> description(description_, description_+sizeof(description_)/sizeof(*description_)); 
	int _ = 0; 
END
CASE(3)
	int points_[] = {25600, 51200, 102400};
	  vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); 
	string description_[] = {"NYY",
 "YNY",
 "YYY",
 "YNN",
 "YYN",
 "NNY",
 "NYN",
 "NNN"};
	  vector <string> description(description_, description_+sizeof(description_)/sizeof(*description_)); 
	int _ = 867560805; 
END
CASE(5)
int points_[] = {30000,60000,110000};
	  vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); 
	string description_[] = {
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
		"YYY",
	};
	  vector <string> description(description_, description_+sizeof(description_)/sizeof(*description_)); 
	int _ = -1; 
END
}
// END CUT HERE