8bf237c40d 2011-10-04 kinaba: #include <iostream> 8bf237c40d 2011-10-04 kinaba: #include <sstream> 8bf237c40d 2011-10-04 kinaba: #include <iomanip> 8bf237c40d 2011-10-04 kinaba: #include <vector> 8bf237c40d 2011-10-04 kinaba: #include <string> 8bf237c40d 2011-10-04 kinaba: #include <map> 8bf237c40d 2011-10-04 kinaba: #include <set> 8bf237c40d 2011-10-04 kinaba: #include <algorithm> 8bf237c40d 2011-10-04 kinaba: #include <numeric> 8bf237c40d 2011-10-04 kinaba: #include <iterator> 8bf237c40d 2011-10-04 kinaba: #include <functional> 8bf237c40d 2011-10-04 kinaba: #include <complex> 8bf237c40d 2011-10-04 kinaba: #include <queue> 8bf237c40d 2011-10-04 kinaba: #include <stack> 8bf237c40d 2011-10-04 kinaba: #include <cmath> 8bf237c40d 2011-10-04 kinaba: #include <cassert> 8bf237c40d 2011-10-04 kinaba: #include <cstring> 8bf237c40d 2011-10-04 kinaba: using namespace std; 8bf237c40d 2011-10-04 kinaba: typedef long long LL; 8bf237c40d 2011-10-04 kinaba: typedef complex<double> CMP; 8bf237c40d 2011-10-04 kinaba: 8bf237c40d 2011-10-04 kinaba: static const int MODVAL = 1000000007; // must be prime for op/ 8bf237c40d 2011-10-04 kinaba: struct mint 8bf237c40d 2011-10-04 kinaba: { 8bf237c40d 2011-10-04 kinaba: int val; 8bf237c40d 2011-10-04 kinaba: mint():val(0){} 8bf237c40d 2011-10-04 kinaba: mint(int x):val(x%MODVAL) {} 8bf237c40d 2011-10-04 kinaba: mint(size_t x):val(x%MODVAL) {} 8bf237c40d 2011-10-04 kinaba: mint(LL x):val(x%MODVAL) {} 8bf237c40d 2011-10-04 kinaba: }; 8bf237c40d 2011-10-04 kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } 8bf237c40d 2011-10-04 kinaba: mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } 8bf237c40d 2011-10-04 kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } 8bf237c40d 2011-10-04 kinaba: mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; } 8bf237c40d 2011-10-04 kinaba: mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); } 8bf237c40d 2011-10-04 kinaba: mint operator+(mint x, mint y) { return x+=y; } 8bf237c40d 2011-10-04 kinaba: mint operator-(mint x, mint y) { return x-=y; } 8bf237c40d 2011-10-04 kinaba: mint operator*(mint x, mint y) { return x*=y; } 8bf237c40d 2011-10-04 kinaba: mint operator/(mint x, mint y) { return x/=y; } 8bf237c40d 2011-10-04 kinaba: vector<mint> FAC_(1,1); 8bf237c40d 2011-10-04 kinaba: mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*FAC_.size() ); return FAC_[n]; } 8bf237c40d 2011-10-04 kinaba: mint C(LL n, LL k) { return k<0 || n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); } 8bf237c40d 2011-10-04 kinaba: 8bf237c40d 2011-10-04 kinaba: template<typename T> 8bf237c40d 2011-10-04 kinaba: struct DP4 8bf237c40d 2011-10-04 kinaba: { 8bf237c40d 2011-10-04 kinaba: int N1, N2, N3, N4; 8bf237c40d 2011-10-04 kinaba: vector<T> data; 8bf237c40d 2011-10-04 kinaba: DP4(int N1, int N2, int N3, int N4, const T& t = T()) 8bf237c40d 2011-10-04 kinaba: : N1(N1), N2(N2), N3(N3), N4(N4), data(N1*N2*N3*N4, t) { assert(data.size()*sizeof(T)<(1<<26)); } 8bf237c40d 2011-10-04 kinaba: T& operator()(int i1, int i2, int i3, int i4) 8bf237c40d 2011-10-04 kinaba: { return data[ (((i1*N2)+i2)*N3+i3)*N4+i4 ]; } 8bf237c40d 2011-10-04 kinaba: void swap(DP4& rhs) 8bf237c40d 2011-10-04 kinaba: { data.swap(rhs.data); } 8bf237c40d 2011-10-04 kinaba: }; 8bf237c40d 2011-10-04 kinaba: 8bf237c40d 2011-10-04 kinaba: class SRMIntermissionPhase { public: 8bf237c40d 2011-10-04 kinaba: int countWays(vector <int> points, vector <string> description) 8bf237c40d 2011-10-04 kinaba: { 8bf237c40d 2011-10-04 kinaba: const int TOTAL = accumulate(points.begin(), points.end(), 0); 8bf237c40d 2011-10-04 kinaba: 8bf237c40d 2011-10-04 kinaba: DP4<mint> patnum(2,2,2,TOTAL+1); 8bf237c40d 2011-10-04 kinaba: int a[3]; 8bf237c40d 2011-10-04 kinaba: for(a[0]=0; a[0]<2; ++a[0]) 8bf237c40d 2011-10-04 kinaba: for(a[1]=0; a[1]<2; ++a[1]) 8bf237c40d 2011-10-04 kinaba: for(a[2]=0; a[2]<2; ++a[2]) 8bf237c40d 2011-10-04 kinaba: { 8bf237c40d 2011-10-04 kinaba: patnum(a[0],a[1],a[2],0) = 1; 8bf237c40d 2011-10-04 kinaba: for(int i=0; i<3; ++i) if(a[i]) { 8bf237c40d 2011-10-04 kinaba: for(int p=1; p<=TOTAL; ++p) 8bf237c40d 2011-10-04 kinaba: patnum(a[0],a[1],a[2],p) += patnum(a[0],a[1],a[2],p-1); 8bf237c40d 2011-10-04 kinaba: for(int p=TOTAL; p>=points[i]+1; --p) 8bf237c40d 2011-10-04 kinaba: 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); 8bf237c40d 2011-10-04 kinaba: for(int p=points[i]; p>=0; --p) 8bf237c40d 2011-10-04 kinaba: patnum(a[0],a[1],a[2],p) = p>0 ? patnum(a[0],a[1],a[2],p-1) : 0; 8bf237c40d 2011-10-04 kinaba: } 8bf237c40d 2011-10-04 kinaba: } 8bf237c40d 2011-10-04 kinaba: 8bf237c40d 2011-10-04 kinaba: vector<mint> dp(TOTAL+2); 8bf237c40d 2011-10-04 kinaba: dp[0] = 1; // -1 8bf237c40d 2011-10-04 kinaba: for(int i=description.size()-1; i>=0; --i) 8bf237c40d 2011-10-04 kinaba: { 8bf237c40d 2011-10-04 kinaba: partial_sum(dp.begin(), dp.end(), dp.begin()); 8bf237c40d 2011-10-04 kinaba: for(int s=TOTAL; s>=0; --s) 8bf237c40d 2011-10-04 kinaba: dp[s+1] = dp[s] * patnum( 8bf237c40d 2011-10-04 kinaba: description[i][0]=='Y', 8bf237c40d 2011-10-04 kinaba: description[i][1]=='Y', 8bf237c40d 2011-10-04 kinaba: description[i][2]=='Y', 8bf237c40d 2011-10-04 kinaba: s 8bf237c40d 2011-10-04 kinaba: ); 8bf237c40d 2011-10-04 kinaba: dp[0] = 0; 8bf237c40d 2011-10-04 kinaba: } 8bf237c40d 2011-10-04 kinaba: return accumulate(dp.begin()+1, dp.end(), mint(0)).val; 8bf237c40d 2011-10-04 kinaba: } 8bf237c40d 2011-10-04 kinaba: }; 8bf237c40d 2011-10-04 kinaba: 8bf237c40d 2011-10-04 kinaba: // BEGIN CUT HERE 8bf237c40d 2011-10-04 kinaba: #include <ctime> 8bf237c40d 2011-10-04 kinaba: double start_time; string timer() 8bf237c40d 2011-10-04 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 8bf237c40d 2011-10-04 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 8bf237c40d 2011-10-04 kinaba: { os << "{ "; 8bf237c40d 2011-10-04 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 8bf237c40d 2011-10-04 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 8bf237c40d 2011-10-04 kinaba: void verify_case(const int& Expected, const int& Received) { 8bf237c40d 2011-10-04 kinaba: bool ok = (Expected == Received); 8bf237c40d 2011-10-04 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 8bf237c40d 2011-10-04 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 8bf237c40d 2011-10-04 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 8bf237c40d 2011-10-04 kinaba: #define END verify_case(_, SRMIntermissionPhase().countWays(points, description));} 8bf237c40d 2011-10-04 kinaba: int main(){ 8bf237c40d 2011-10-04 kinaba: 8bf237c40d 2011-10-04 kinaba: CASE(4) 8bf237c40d 2011-10-04 kinaba: int points_[] = {1,2,3}; 8bf237c40d 2011-10-04 kinaba: vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); 8bf237c40d 2011-10-04 kinaba: string description_[] = {"YNN","NNN"}; 8bf237c40d 2011-10-04 kinaba: vector <string> description(description_, description_+sizeof(description_)/sizeof(*description_)); 8bf237c40d 2011-10-04 kinaba: int _ = 1; 8bf237c40d 2011-10-04 kinaba: END 8bf237c40d 2011-10-04 kinaba: CASE(0) 8bf237c40d 2011-10-04 kinaba: int points_[] = {25000, 50000, 100000}; 8bf237c40d 2011-10-04 kinaba: vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); 8bf237c40d 2011-10-04 kinaba: string description_[] = {"YNN", 8bf237c40d 2011-10-04 kinaba: "NNN"}; 8bf237c40d 2011-10-04 kinaba: vector <string> description(description_, description_+sizeof(description_)/sizeof(*description_)); 8bf237c40d 2011-10-04 kinaba: int _ = 25000; 8bf237c40d 2011-10-04 kinaba: END 8bf237c40d 2011-10-04 kinaba: CASE(1) 8bf237c40d 2011-10-04 kinaba: int points_[] = {30000, 60000, 90000}; 8bf237c40d 2011-10-04 kinaba: vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); 8bf237c40d 2011-10-04 kinaba: string description_[] = {"NYN", 8bf237c40d 2011-10-04 kinaba: "NYN"}; 8bf237c40d 2011-10-04 kinaba: vector <string> description(description_, description_+sizeof(description_)/sizeof(*description_)); 8bf237c40d 2011-10-04 kinaba: int _ = 799969993; 8bf237c40d 2011-10-04 kinaba: END 8bf237c40d 2011-10-04 kinaba: CASE(2) 8bf237c40d 2011-10-04 kinaba: int points_[] = {25000, 45000, 110000}; 8bf237c40d 2011-10-04 kinaba: vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); 8bf237c40d 2011-10-04 kinaba: string description_[] = {"NNN", 8bf237c40d 2011-10-04 kinaba: "YYY"}; 8bf237c40d 2011-10-04 kinaba: vector <string> description(description_, description_+sizeof(description_)/sizeof(*description_)); 8bf237c40d 2011-10-04 kinaba: int _ = 0; 8bf237c40d 2011-10-04 kinaba: END 8bf237c40d 2011-10-04 kinaba: CASE(3) 8bf237c40d 2011-10-04 kinaba: int points_[] = {25600, 51200, 102400}; 8bf237c40d 2011-10-04 kinaba: vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); 8bf237c40d 2011-10-04 kinaba: string description_[] = {"NYY", 8bf237c40d 2011-10-04 kinaba: "YNY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YNN", 8bf237c40d 2011-10-04 kinaba: "YYN", 8bf237c40d 2011-10-04 kinaba: "NNY", 8bf237c40d 2011-10-04 kinaba: "NYN", 8bf237c40d 2011-10-04 kinaba: "NNN"}; 8bf237c40d 2011-10-04 kinaba: vector <string> description(description_, description_+sizeof(description_)/sizeof(*description_)); 8bf237c40d 2011-10-04 kinaba: int _ = 867560805; 8bf237c40d 2011-10-04 kinaba: END 8bf237c40d 2011-10-04 kinaba: CASE(5) 8bf237c40d 2011-10-04 kinaba: int points_[] = {30000,60000,110000}; 8bf237c40d 2011-10-04 kinaba: vector <int> points(points_, points_+sizeof(points_)/sizeof(*points_)); 8bf237c40d 2011-10-04 kinaba: string description_[] = { 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: "YYY", 8bf237c40d 2011-10-04 kinaba: }; 8bf237c40d 2011-10-04 kinaba: vector <string> description(description_, description_+sizeof(description_)/sizeof(*description_)); 8bf237c40d 2011-10-04 kinaba: int _ = -1; 8bf237c40d 2011-10-04 kinaba: END 8bf237c40d 2011-10-04 kinaba: } 8bf237c40d 2011-10-04 kinaba: // END CUT HERE