Artifact Content
Not logged in

Artifact f01284ac275c4ca0015bc739b45b39589941fc3b


#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 <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

static const unsigned MODVAL = 1000000007;
struct mint
{
	unsigned val;
	mint():val(0){}
	mint(int      x):val(x%MODVAL) {}
	mint(unsigned 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 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; }

// nCk :: O(1) time, O(n^2) space.
vector< vector<mint> > CP_;
mint C(int n, int k) {
	while( CP_.size() <= n ) {
		int nn = CP_.size();
		CP_.push_back(vector<mint>(nn+1,1));
		for(int kk=1; kk<nn; ++kk)
			CP_[nn][kk] = CP_[nn-1][kk-1] + CP_[nn-1][kk];
	}
	return k<0 || n<k ? 0 : CP_[n][k];
}

typedef tuple<int,int,int> Vec;
inline int operator*(Vec v, Vec u) {
	return get<0>(v)*get<0>(u) + get<1>(v)*get<1>(u) + get<2>(v)*get<2>(u);
}

class RockPaperScissorsMagic { public:
	int count(int W, int L, int T, vector <int> card)
	{
		const int N0 = std::count(card.begin(), card.end(), 0);
		const int N1 = std::count(card.begin(), card.end(), 1);
		const int N2 = std::count(card.begin(), card.end(), 2);

		mint ans = 0;
		for(int x1=0; x1<=N0; ++x1)
		for(int x2=0; x1+x2<=N0; ++x2)
		for(int y1=0; y1<=N1; ++y1)
		for(int y2=0; y1+y2<=N1; ++y2)
		for(int z1=0; z1<=N2; ++z1)
		for(int z2=0; z1+z2<=N2; ++z2) {
			int x3,y3,z3;
			Vec x(x1, x2, x3=N0-x1-x2);
			Vec y(y1, y2, y3=N1-y1-y2);
			Vec z(z1, z2, z3=N2-z1-z2);
			Vec TLW(T,L,W);
			Vec WTL(W,T,L);
			Vec LTW(L,T,W);
			if(TLW*x+WTL*y != TLW*y+WTL*x) continue;
			if(T!=L && x1-x2!=y1-y2) continue;
			if(W!=L && x1-x3!=y1-y3) continue;
			if(TLW*x+WTL*z != TLW*z+WTL*x) continue;
			if(T!=L && x1-x2!=z1-z2) continue;
			if(W!=L && x1-x3!=z1-z3) continue;

			ans += C(N0, x1) * C(N0-x1, x2)
				* C(N1, y1) * C(N1-y1, y2)
				* C(N2, z1) * C(N2-z1, z2);
		}
		return ans.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(_, RockPaperScissorsMagic().count(win, lose, tie, card));}
int main(){

CASE(0)
	int win = 2; 
	int lose = 0; 
	int tie = 1; 
	int card_[] = {0,1,2};
	  vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 
	int _ = 3; 
END
CASE(1)
	int win = 2; 
	int lose = 0; 
	int tie = 1; 
	int card_[] = {0,0,0};
	  vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 
	int _ = 6; 
END
CASE(2)
	int win = 0; 
	int lose = 0; 
	int tie = 0; 
	int card_[] = {1,0,2,2,2,0};
	  vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 
	int _ = 729; 
END
CASE(3)
	int win = 514; 
	int lose = 451; 
	int tie = 145; 
	int card_[] = {0,0,0,0,0,1,1,1,1,1,1,2,2,2};
	  vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 
	int _ = 0; 
END
CASE(4)
	int win = 3; 
	int lose = 6; 
	int tie = 9; 
	int card_[] = {0,0,0,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2};
	  vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 
	int _ = 2336040; 
END
CASE(5)
	int win = 514; 
	int lose = 451; 
	int tie = 145; 
	int card_[] = {0,0,0,1,1,1,1,1,1,2,2,2,2,2,2};
	  vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 
	int _ = 116100; 
END
/*
CASE(6)
	int win = ; 
	int lose = ; 
	int tie = ; 
	int card_[] = ;
	  vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 
	int _ = ; 
END
CASE(7)
	int win = ; 
	int lose = ; 
	int tie = ; 
	int card_[] = ;
	  vector <int> card(card_, card_+sizeof(card_)/sizeof(*card_)); 
	int _ = ; 
END
*/
}
// END CUT HERE