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