109f2a9050 2012-09-08 kinaba: #include <iostream> 109f2a9050 2012-09-08 kinaba: #include <sstream> 109f2a9050 2012-09-08 kinaba: #include <iomanip> 109f2a9050 2012-09-08 kinaba: #include <vector> 109f2a9050 2012-09-08 kinaba: #include <string> 109f2a9050 2012-09-08 kinaba: #include <map> 109f2a9050 2012-09-08 kinaba: #include <set> 109f2a9050 2012-09-08 kinaba: #include <algorithm> 109f2a9050 2012-09-08 kinaba: #include <numeric> 109f2a9050 2012-09-08 kinaba: #include <iterator> 109f2a9050 2012-09-08 kinaba: #include <functional> 109f2a9050 2012-09-08 kinaba: #include <complex> 109f2a9050 2012-09-08 kinaba: #include <queue> 109f2a9050 2012-09-08 kinaba: #include <stack> 109f2a9050 2012-09-08 kinaba: #include <cmath> 109f2a9050 2012-09-08 kinaba: #include <cassert> 109f2a9050 2012-09-08 kinaba: using namespace std; 109f2a9050 2012-09-08 kinaba: typedef long long LL; 109f2a9050 2012-09-08 kinaba: typedef long double LD; 109f2a9050 2012-09-08 kinaba: typedef complex<LD> CMP; 109f2a9050 2012-09-08 kinaba: 109f2a9050 2012-09-08 kinaba: static const unsigned MODVAL = 555555555; 109f2a9050 2012-09-08 kinaba: struct mint 109f2a9050 2012-09-08 kinaba: { 109f2a9050 2012-09-08 kinaba: unsigned val; 109f2a9050 2012-09-08 kinaba: mint():val(0){} 109f2a9050 2012-09-08 kinaba: mint(int x):val(x%MODVAL) {} 109f2a9050 2012-09-08 kinaba: mint(unsigned x):val(x%MODVAL) {} 109f2a9050 2012-09-08 kinaba: mint(LL x):val(x%MODVAL) {} 109f2a9050 2012-09-08 kinaba: }; 109f2a9050 2012-09-08 kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } 109f2a9050 2012-09-08 kinaba: mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } 109f2a9050 2012-09-08 kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } 109f2a9050 2012-09-08 kinaba: mint operator+(mint x, mint y) { return x+=y; } 109f2a9050 2012-09-08 kinaba: mint operator-(mint x, mint y) { return x-=y; } 109f2a9050 2012-09-08 kinaba: mint operator*(mint x, mint y) { return x*=y; } 109f2a9050 2012-09-08 kinaba: mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; } 109f2a9050 2012-09-08 kinaba: 109f2a9050 2012-09-08 kinaba: vector< vector<mint> > CP_; 109f2a9050 2012-09-08 kinaba: mint C(LL n, LL k) { 109f2a9050 2012-09-08 kinaba: while( CP_.size() <= n ) { 109f2a9050 2012-09-08 kinaba: int nn = CP_.size(); 109f2a9050 2012-09-08 kinaba: CP_.push_back(vector<mint>(nn+1,1)); 109f2a9050 2012-09-08 kinaba: for(int kk=1; kk<nn; ++kk) 109f2a9050 2012-09-08 kinaba: CP_[nn][kk] = CP_[nn-1][kk-1] + CP_[nn-1][kk]; 109f2a9050 2012-09-08 kinaba: } 109f2a9050 2012-09-08 kinaba: return k<0 || n<k ? 0 : CP_[n][k]; 109f2a9050 2012-09-08 kinaba: } 109f2a9050 2012-09-08 kinaba: 109f2a9050 2012-09-08 kinaba: class XorBoard { public: 109f2a9050 2012-09-08 kinaba: int count(int H, int W, int Rcount, int Ccount, int S) 109f2a9050 2012-09-08 kinaba: { 109f2a9050 2012-09-08 kinaba: vector<mint> xx(W+1), yy(H+1); 109f2a9050 2012-09-08 kinaba: for(int x=0; x<=W; ++x) 109f2a9050 2012-09-08 kinaba: xx[x] = subProblem(W, Ccount, x); 109f2a9050 2012-09-08 kinaba: for(int y=0; y<=H; ++y) 109f2a9050 2012-09-08 kinaba: yy[y] = subProblem(H, Rcount, y); 109f2a9050 2012-09-08 kinaba: 109f2a9050 2012-09-08 kinaba: mint cnt = 0; 109f2a9050 2012-09-08 kinaba: for(int x=0; x<=W; ++x) 109f2a9050 2012-09-08 kinaba: for(int y=0; y<=H; ++y) 109f2a9050 2012-09-08 kinaba: if( x*(H-y)+(W-x)*y == S ) 109f2a9050 2012-09-08 kinaba: cnt += xx[x]*yy[y]; 109f2a9050 2012-09-08 kinaba: return cnt.val; 109f2a9050 2012-09-08 kinaba: } 109f2a9050 2012-09-08 kinaba: 109f2a9050 2012-09-08 kinaba: mint subProblem(int Z, int T, int k) 109f2a9050 2012-09-08 kinaba: { 109f2a9050 2012-09-08 kinaba: // Z objects 109f2a9050 2012-09-08 kinaba: // T flips 109f2a9050 2012-09-08 kinaba: // k of them flipped odd # of times 109f2a9050 2012-09-08 kinaba: // Z-k even 109f2a9050 2012-09-08 kinaba: if( T < k ) 109f2a9050 2012-09-08 kinaba: return 0; 109f2a9050 2012-09-08 kinaba: T -= k; 109f2a9050 2012-09-08 kinaba: if( T%2 != 0 ) 109f2a9050 2012-09-08 kinaba: return 0; 109f2a9050 2012-09-08 kinaba: T /= 2; 109f2a9050 2012-09-08 kinaba: mint cc = C(Z, k); 109f2a9050 2012-09-08 kinaba: // Z obj 109f2a9050 2012-09-08 kinaba: // T flips 109f2a9050 2012-09-08 kinaba: return cc * C(T+Z-1, Z-1); 109f2a9050 2012-09-08 kinaba: } 109f2a9050 2012-09-08 kinaba: }; 109f2a9050 2012-09-08 kinaba: 109f2a9050 2012-09-08 kinaba: // BEGIN CUT HERE 109f2a9050 2012-09-08 kinaba: #include <ctime> 109f2a9050 2012-09-08 kinaba: double start_time; string timer() 109f2a9050 2012-09-08 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 109f2a9050 2012-09-08 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 109f2a9050 2012-09-08 kinaba: { os << "{ "; 109f2a9050 2012-09-08 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 109f2a9050 2012-09-08 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 109f2a9050 2012-09-08 kinaba: void verify_case(const int& Expected, const int& Received) { 109f2a9050 2012-09-08 kinaba: bool ok = (Expected == Received); 109f2a9050 2012-09-08 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 109f2a9050 2012-09-08 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 109f2a9050 2012-09-08 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 109f2a9050 2012-09-08 kinaba: #define END verify_case(_, XorBoard().count(H, W, Rcount, Ccount, S));} 109f2a9050 2012-09-08 kinaba: int main(){ 109f2a9050 2012-09-08 kinaba: 109f2a9050 2012-09-08 kinaba: CASE(0) 109f2a9050 2012-09-08 kinaba: int H = 2; 109f2a9050 2012-09-08 kinaba: int W = 2; 109f2a9050 2012-09-08 kinaba: int Rcount = 2; 109f2a9050 2012-09-08 kinaba: int Ccount = 2; 109f2a9050 2012-09-08 kinaba: int S = 4; 109f2a9050 2012-09-08 kinaba: int _ = 4; 109f2a9050 2012-09-08 kinaba: END 109f2a9050 2012-09-08 kinaba: CASE(1) 109f2a9050 2012-09-08 kinaba: int H = 2; 109f2a9050 2012-09-08 kinaba: int W = 2; 109f2a9050 2012-09-08 kinaba: int Rcount = 0; 109f2a9050 2012-09-08 kinaba: int Ccount = 0; 109f2a9050 2012-09-08 kinaba: int S = 1; 109f2a9050 2012-09-08 kinaba: int _ = 0; 109f2a9050 2012-09-08 kinaba: END 109f2a9050 2012-09-08 kinaba: CASE(2) 109f2a9050 2012-09-08 kinaba: int H = 10; 109f2a9050 2012-09-08 kinaba: int W = 20; 109f2a9050 2012-09-08 kinaba: int Rcount = 50; 109f2a9050 2012-09-08 kinaba: int Ccount = 40; 109f2a9050 2012-09-08 kinaba: int S = 200; 109f2a9050 2012-09-08 kinaba: int _ = 333759825; 109f2a9050 2012-09-08 kinaba: END 109f2a9050 2012-09-08 kinaba: CASE(3) 109f2a9050 2012-09-08 kinaba: int H = 1200; 109f2a9050 2012-09-08 kinaba: int W = 1000; 109f2a9050 2012-09-08 kinaba: int Rcount = 800; 109f2a9050 2012-09-08 kinaba: int Ccount = 600; 109f2a9050 2012-09-08 kinaba: int S = 4000; 109f2a9050 2012-09-08 kinaba: int _ = 96859710; 109f2a9050 2012-09-08 kinaba: END 109f2a9050 2012-09-08 kinaba: CASE(4) 109f2a9050 2012-09-08 kinaba: int H = 555; 109f2a9050 2012-09-08 kinaba: int W = 555; 109f2a9050 2012-09-08 kinaba: int Rcount = 555; 109f2a9050 2012-09-08 kinaba: int Ccount = 555; 109f2a9050 2012-09-08 kinaba: int S = 5550; 109f2a9050 2012-09-08 kinaba: int _ = 549361755; 109f2a9050 2012-09-08 kinaba: END 109f2a9050 2012-09-08 kinaba: CASE(5) 109f2a9050 2012-09-08 kinaba: int H = 1555; 109f2a9050 2012-09-08 kinaba: int W = 1555; 109f2a9050 2012-09-08 kinaba: int Rcount = 755; 109f2a9050 2012-09-08 kinaba: int Ccount = 755; 109f2a9050 2012-09-08 kinaba: int S = 555555; 109f2a9050 2012-09-08 kinaba: int _ = -1; 109f2a9050 2012-09-08 kinaba: END 109f2a9050 2012-09-08 kinaba: /* 109f2a9050 2012-09-08 kinaba: CASE(6) 109f2a9050 2012-09-08 kinaba: int H = ; 109f2a9050 2012-09-08 kinaba: int W = ; 109f2a9050 2012-09-08 kinaba: int Rcount = ; 109f2a9050 2012-09-08 kinaba: int Ccount = ; 109f2a9050 2012-09-08 kinaba: int S = ; 109f2a9050 2012-09-08 kinaba: int _ = ; 109f2a9050 2012-09-08 kinaba: END 109f2a9050 2012-09-08 kinaba: */ 109f2a9050 2012-09-08 kinaba: } 109f2a9050 2012-09-08 kinaba: // END CUT HERE