197afdc1d0 2015-03-26 kinaba: #include <iostream> 197afdc1d0 2015-03-26 kinaba: #include <sstream> 197afdc1d0 2015-03-26 kinaba: #include <iomanip> 197afdc1d0 2015-03-26 kinaba: #include <vector> 197afdc1d0 2015-03-26 kinaba: #include <string> 197afdc1d0 2015-03-26 kinaba: #include <map> 197afdc1d0 2015-03-26 kinaba: #include <set> 197afdc1d0 2015-03-26 kinaba: #include <algorithm> 197afdc1d0 2015-03-26 kinaba: #include <numeric> 197afdc1d0 2015-03-26 kinaba: #include <iterator> 197afdc1d0 2015-03-26 kinaba: #include <functional> 197afdc1d0 2015-03-26 kinaba: #include <complex> 197afdc1d0 2015-03-26 kinaba: #include <queue> 197afdc1d0 2015-03-26 kinaba: #include <stack> 197afdc1d0 2015-03-26 kinaba: #include <cmath> 197afdc1d0 2015-03-26 kinaba: #include <cassert> 197afdc1d0 2015-03-26 kinaba: #include <tuple> 197afdc1d0 2015-03-26 kinaba: using namespace std; 197afdc1d0 2015-03-26 kinaba: typedef long long LL; 197afdc1d0 2015-03-26 kinaba: typedef complex<double> CMP; 197afdc1d0 2015-03-26 kinaba: 197afdc1d0 2015-03-26 kinaba: static const unsigned MODVAL = 1000000007; 197afdc1d0 2015-03-26 kinaba: struct mint 197afdc1d0 2015-03-26 kinaba: { 197afdc1d0 2015-03-26 kinaba: unsigned val; 197afdc1d0 2015-03-26 kinaba: mint():val(0){} 197afdc1d0 2015-03-26 kinaba: mint(int x):val(x%MODVAL) {} 197afdc1d0 2015-03-26 kinaba: mint(unsigned x):val(x%MODVAL) {} 197afdc1d0 2015-03-26 kinaba: mint(LL x):val(x%MODVAL) {} 197afdc1d0 2015-03-26 kinaba: }; 197afdc1d0 2015-03-26 kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } 197afdc1d0 2015-03-26 kinaba: mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } 197afdc1d0 2015-03-26 kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } 197afdc1d0 2015-03-26 kinaba: mint operator+(mint x, mint y) { return x+=y; } 197afdc1d0 2015-03-26 kinaba: mint operator-(mint x, mint y) { return x-=y; } 197afdc1d0 2015-03-26 kinaba: mint operator*(mint x, mint y) { return x*=y; } 197afdc1d0 2015-03-26 kinaba: 197afdc1d0 2015-03-26 kinaba: // nCk :: O(1) time, O(n^2) space. 197afdc1d0 2015-03-26 kinaba: vector< vector<mint> > CP_; 197afdc1d0 2015-03-26 kinaba: mint C(int n, int k) { 197afdc1d0 2015-03-26 kinaba: while( CP_.size() <= n ) { 197afdc1d0 2015-03-26 kinaba: int nn = CP_.size(); 197afdc1d0 2015-03-26 kinaba: CP_.push_back(vector<mint>(nn+1,1)); 197afdc1d0 2015-03-26 kinaba: for(int kk=1; kk<nn; ++kk) 197afdc1d0 2015-03-26 kinaba: CP_[nn][kk] = CP_[nn-1][kk-1] + CP_[nn-1][kk]; 197afdc1d0 2015-03-26 kinaba: } 197afdc1d0 2015-03-26 kinaba: return k<0 || n<k ? 0 : CP_[n][k]; 197afdc1d0 2015-03-26 kinaba: } 197afdc1d0 2015-03-26 kinaba: 197afdc1d0 2015-03-26 kinaba: typedef tuple<int,int,int> Vec; 197afdc1d0 2015-03-26 kinaba: inline int operator*(Vec v, Vec u) { 197afdc1d0 2015-03-26 kinaba: return get<0>(v)*get<0>(u) + get<1>(v)*get<1>(u) + get<2>(v)*get<2>(u); 197afdc1d0 2015-03-26 kinaba: } 197afdc1d0 2015-03-26 kinaba: 197afdc1d0 2015-03-26 kinaba: class RockPaperScissorsMagic { public: 197afdc1d0 2015-03-26 kinaba: int count(int W, int L, int T, vector <int> card) 197afdc1d0 2015-03-26 kinaba: { 197afdc1d0 2015-03-26 kinaba: const int N0 = std::count(card.begin(), card.end(), 0); 197afdc1d0 2015-03-26 kinaba: const int N1 = std::count(card.begin(), card.end(), 1); 197afdc1d0 2015-03-26 kinaba: const int N2 = std::count(card.begin(), card.end(), 2); 197afdc1d0 2015-03-26 kinaba: 197afdc1d0 2015-03-26 kinaba: mint ans = 0; 197afdc1d0 2015-03-26 kinaba: for(int x1=0; x1<=N0; ++x1) 197afdc1d0 2015-03-26 kinaba: for(int x2=0; x1+x2<=N0; ++x2) 197afdc1d0 2015-03-26 kinaba: for(int y1=0; y1<=N1; ++y1) 197afdc1d0 2015-03-26 kinaba: for(int y2=0; y1+y2<=N1; ++y2) 197afdc1d0 2015-03-26 kinaba: for(int z1=0; z1<=N2; ++z1) 197afdc1d0 2015-03-26 kinaba: for(int z2=0; z1+z2<=N2; ++z2) { 197afdc1d0 2015-03-26 kinaba: int x3,y3,z3; 197afdc1d0 2015-03-26 kinaba: Vec x(x1, x2, x3=N0-x1-x2); 197afdc1d0 2015-03-26 kinaba: Vec y(y1, y2, y3=N1-y1-y2); 197afdc1d0 2015-03-26 kinaba: Vec z(z1, z2, z3=N2-z1-z2); 197afdc1d0 2015-03-26 kinaba: Vec TLW(T,L,W); 197afdc1d0 2015-03-26 kinaba: Vec WTL(W,T,L); 197afdc1d0 2015-03-26 kinaba: Vec LTW(L,T,W); 197afdc1d0 2015-03-26 kinaba: if(TLW*x+WTL*y != TLW*y+WTL*x) continue; 197afdc1d0 2015-03-26 kinaba: if(T!=L && x1-x2!=y1-y2) continue; 197afdc1d0 2015-03-26 kinaba: if(W!=L && x1-x3!=y1-y3) continue; 197afdc1d0 2015-03-26 kinaba: if(TLW*x+WTL*z != TLW*z+WTL*x) continue; 197afdc1d0 2015-03-26 kinaba: if(T!=L && x1-x2!=z1-z2) continue; 197afdc1d0 2015-03-26 kinaba: if(W!=L && x1-x3!=z1-z3) continue; 197afdc1d0 2015-03-26 kinaba: 197afdc1d0 2015-03-26 kinaba: ans += C(N0, x1) * C(N0-x1, x2) 197afdc1d0 2015-03-26 kinaba: * C(N1, y1) * C(N1-y1, y2) 197afdc1d0 2015-03-26 kinaba: * C(N2, z1) * C(N2-z1, z2); 197afdc1d0 2015-03-26 kinaba: } 197afdc1d0 2015-03-26 kinaba: return ans.val; 197afdc1d0 2015-03-26 kinaba: } 197afdc1d0 2015-03-26 kinaba: }; 197afdc1d0 2015-03-26 kinaba: 197afdc1d0 2015-03-26 kinaba: // BEGIN CUT HERE 197afdc1d0 2015-03-26 kinaba: #include <ctime> 197afdc1d0 2015-03-26 kinaba: double start_time; string timer() 197afdc1d0 2015-03-26 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 197afdc1d0 2015-03-26 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 197afdc1d0 2015-03-26 kinaba: { os << "{ "; 197afdc1d0 2015-03-26 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 197afdc1d0 2015-03-26 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 197afdc1d0 2015-03-26 kinaba: void verify_case(const int& Expected, const int& Received) { 197afdc1d0 2015-03-26 kinaba: bool ok = (Expected == Received); 197afdc1d0 2015-03-26 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 197afdc1d0 2015-03-26 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 197afdc1d0 2015-03-26 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 197afdc1d0 2015-03-26 kinaba: #define END verify_case(_, RockPaperScissorsMagic().count(win, lose, tie, card));} 197afdc1d0 2015-03-26 kinaba: int main(){ 197afdc1d0 2015-03-26 kinaba: 197afdc1d0 2015-03-26 kinaba: CASE(0) 197afdc1d0 2015-03-26 kinaba: int win = 2; 197afdc1d0 2015-03-26 kinaba: int lose = 0; 197afdc1d0 2015-03-26 kinaba: int tie = 1; 197afdc1d0 2015-03-26 kinaba: int card_[] = {0,1,2}; 197afdc1d0 2015-03-26 kinaba: vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 197afdc1d0 2015-03-26 kinaba: int _ = 3; 197afdc1d0 2015-03-26 kinaba: END 197afdc1d0 2015-03-26 kinaba: CASE(1) 197afdc1d0 2015-03-26 kinaba: int win = 2; 197afdc1d0 2015-03-26 kinaba: int lose = 0; 197afdc1d0 2015-03-26 kinaba: int tie = 1; 197afdc1d0 2015-03-26 kinaba: int card_[] = {0,0,0}; 197afdc1d0 2015-03-26 kinaba: vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 197afdc1d0 2015-03-26 kinaba: int _ = 6; 197afdc1d0 2015-03-26 kinaba: END 197afdc1d0 2015-03-26 kinaba: CASE(2) 197afdc1d0 2015-03-26 kinaba: int win = 0; 197afdc1d0 2015-03-26 kinaba: int lose = 0; 197afdc1d0 2015-03-26 kinaba: int tie = 0; 197afdc1d0 2015-03-26 kinaba: int card_[] = {1,0,2,2,2,0}; 197afdc1d0 2015-03-26 kinaba: vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 197afdc1d0 2015-03-26 kinaba: int _ = 729; 197afdc1d0 2015-03-26 kinaba: END 197afdc1d0 2015-03-26 kinaba: CASE(3) 197afdc1d0 2015-03-26 kinaba: int win = 514; 197afdc1d0 2015-03-26 kinaba: int lose = 451; 197afdc1d0 2015-03-26 kinaba: int tie = 145; 197afdc1d0 2015-03-26 kinaba: int card_[] = {0,0,0,0,0,1,1,1,1,1,1,2,2,2}; 197afdc1d0 2015-03-26 kinaba: vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 197afdc1d0 2015-03-26 kinaba: int _ = 0; 197afdc1d0 2015-03-26 kinaba: END 197afdc1d0 2015-03-26 kinaba: CASE(4) 197afdc1d0 2015-03-26 kinaba: int win = 3; 197afdc1d0 2015-03-26 kinaba: int lose = 6; 197afdc1d0 2015-03-26 kinaba: int tie = 9; 197afdc1d0 2015-03-26 kinaba: int card_[] = {0,0,0,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2}; 197afdc1d0 2015-03-26 kinaba: vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 197afdc1d0 2015-03-26 kinaba: int _ = 2336040; 197afdc1d0 2015-03-26 kinaba: END 197afdc1d0 2015-03-26 kinaba: CASE(5) 197afdc1d0 2015-03-26 kinaba: int win = 514; 197afdc1d0 2015-03-26 kinaba: int lose = 451; 197afdc1d0 2015-03-26 kinaba: int tie = 145; 197afdc1d0 2015-03-26 kinaba: int card_[] = {0,0,0,1,1,1,1,1,1,2,2,2,2,2,2}; 197afdc1d0 2015-03-26 kinaba: vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 197afdc1d0 2015-03-26 kinaba: int _ = 116100; 197afdc1d0 2015-03-26 kinaba: END 197afdc1d0 2015-03-26 kinaba: /* 197afdc1d0 2015-03-26 kinaba: CASE(6) 197afdc1d0 2015-03-26 kinaba: int win = ; 197afdc1d0 2015-03-26 kinaba: int lose = ; 197afdc1d0 2015-03-26 kinaba: int tie = ; 197afdc1d0 2015-03-26 kinaba: int card_[] = ; 197afdc1d0 2015-03-26 kinaba: vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 197afdc1d0 2015-03-26 kinaba: int _ = ; 197afdc1d0 2015-03-26 kinaba: END 197afdc1d0 2015-03-26 kinaba: CASE(7) 197afdc1d0 2015-03-26 kinaba: int win = ; 197afdc1d0 2015-03-26 kinaba: int lose = ; 197afdc1d0 2015-03-26 kinaba: int tie = ; 197afdc1d0 2015-03-26 kinaba: int card_[] = ; 197afdc1d0 2015-03-26 kinaba: vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 197afdc1d0 2015-03-26 kinaba: int _ = ; 197afdc1d0 2015-03-26 kinaba: END 197afdc1d0 2015-03-26 kinaba: */ 197afdc1d0 2015-03-26 kinaba: } 197afdc1d0 2015-03-26 kinaba: // END CUT HERE