Artifact Content
Not logged in

Artifact d81e904d5ff64153609b4f36ae7d4030d9a8b1db


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

static const unsigned MODVAL = 555555555;
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; }
mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; }

vector< vector<mint> > CP_;
mint C(LL n, LL 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];
}

class XorBoard { public:
	int count(int H, int W, int Rcount, int Ccount, int S)
	{
		vector<mint> xx(W+1), yy(H+1);
		for(int x=0; x<=W; ++x)
			xx[x] = subProblem(W, Ccount, x);
		for(int y=0; y<=H; ++y)
			yy[y] = subProblem(H, Rcount, y);

		mint cnt = 0;
		for(int x=0; x<=W; ++x)
		for(int y=0; y<=H; ++y)
			if( x*(H-y)+(W-x)*y == S )
				cnt += xx[x]*yy[y];
		return cnt.val;
	}

	mint subProblem(int Z, int T, int k)
	{
		// Z objects
		// T flips
		// k of them flipped odd # of times
		// Z-k even
		if( T < k )
			return 0;
		T -= k;
		if( T%2 != 0 )
			return 0;
		T /= 2;
		mint cc = C(Z, k);
		// Z obj
		// T flips
		return cc * C(T+Z-1, Z-1);
	}
};

// 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(_, XorBoard().count(H, W, Rcount, Ccount, S));}
int main(){

CASE(0)
	int H = 2; 
	int W = 2; 
	int Rcount = 2; 
	int Ccount = 2; 
	int S = 4; 
	int _ = 4; 
END
CASE(1)
	int H = 2; 
	int W = 2; 
	int Rcount = 0; 
	int Ccount = 0; 
	int S = 1; 
	int _ = 0; 
END
CASE(2)
	int H = 10; 
	int W = 20; 
	int Rcount = 50; 
	int Ccount = 40; 
	int S = 200; 
	int _ = 333759825; 
END
CASE(3)
	int H = 1200; 
	int W = 1000; 
	int Rcount = 800; 
	int Ccount = 600; 
	int S = 4000; 
	int _ = 96859710; 
END
CASE(4)
	int H = 555; 
	int W = 555; 
	int Rcount = 555; 
	int Ccount = 555; 
	int S = 5550; 
	int _ = 549361755; 
END
CASE(5)
	int H = 1555; 
	int W = 1555; 
	int Rcount = 755; 
	int Ccount = 755; 
	int S = 555555; 
	int _ = -1; 
END
/*
CASE(6)
	int H = ; 
	int W = ; 
	int Rcount = ; 
	int Ccount = ; 
	int S = ; 
	int _ = ; 
END
*/
}
// END CUT HERE