Artifact Content
Not logged in

Artifact 9a8c214df95651f474733d47d7267fde5c40c5a0


#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 int MODVAL = 1000000007;
class BagAndCards { public:
	int getHash(int n, int m, int x, int a, int b, int c, string isGood)
	{
		vector<vector<int>> count(n, vector<int>(m, 0));
		for(int i=0; i<n; ++i)
		for(int j=0; j<m; ++j) {
			count[i][j] = x;
			x = int(((LL(x) * a + b) ^ c) % MODVAL);
		}

		int total_ans = 0;
		for(int i=0; i<n; ++i)
		{
			vector<LL> mult(m);
			for(int c1=0; c1<m; ++c1)
			for(int c2=0; c2<m; ++c2)
				if(isGood[c1+c2]=='Y')
					mult[c2] += count[i][c1];
			for(int c=0; c<m; ++c)
				mult[c] %= MODVAL;

			for(int k=i+1; k<n; ++k)
			{
				LL ans = 0;
				for(int c=0; c<m; ++c)
					ans += count[k][c] * mult[c] % MODVAL;
				total_ans ^= int(ans % MODVAL);
			}
		}
		return total_ans;
	}
};

// 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(_, BagAndCards().getHash(n, m, x, a, b, c, isGood));}
int main(){

CASE(0)
	int n = 2; 
	int m = 4; 
	int x = 1; 
	int a = 1; 
	int b = 0; 
	int c = 0; 
	string isGood = "NNYYNYN"; 
	int _ = 9; 
END
CASE(1)
	int n = 3; 
	int m = 5; 
	int x = 1; 
	int a = 1; 
	int b = 1; 
	int c = 2; 
	string isGood = "NNYYNYNYN"; 
	int _ = 1532; 
END
CASE(2)
	int n = 10; 
	int m = 20; 
	int x = 111; 
	int a = 222; 
	int b = 333; 
	int c = 444; 
	string isGood = "NNNNNYYYNNNYYYYYYNNYYYYNNNNYNNYYYNNNYYN" ; 
	int _ = 450750683; 
END
CASE(3)
	int n = 2; 
	int m = 2; 
	int x = 1; 
	int a = 1; 
	int b = 0; 
	int c = 0; 
	string isGood = "NNY"; 
	int _ = 1; 
END
/*
CASE(4)
	int n = ; 
	int m = ; 
	int x = ; 
	int a = ; 
	int b = ; 
	int c = ; 
	string isGood = ; 
	int _ = ; 
END
CASE(5)
	int n = ; 
	int m = ; 
	int x = ; 
	int a = ; 
	int b = ; 
	int c = ; 
	string isGood = ; 
	int _ = ; 
END
*/
}
// END CUT HERE