2024b9fa5d 2016-01-23 kinaba: #include <iostream> 2024b9fa5d 2016-01-23 kinaba: #include <sstream> 2024b9fa5d 2016-01-23 kinaba: #include <iomanip> 2024b9fa5d 2016-01-23 kinaba: #include <vector> 2024b9fa5d 2016-01-23 kinaba: #include <string> 2024b9fa5d 2016-01-23 kinaba: #include <map> 2024b9fa5d 2016-01-23 kinaba: #include <set> 2024b9fa5d 2016-01-23 kinaba: #include <algorithm> 2024b9fa5d 2016-01-23 kinaba: #include <numeric> 2024b9fa5d 2016-01-23 kinaba: #include <iterator> 2024b9fa5d 2016-01-23 kinaba: #include <functional> 2024b9fa5d 2016-01-23 kinaba: #include <complex> 2024b9fa5d 2016-01-23 kinaba: #include <queue> 2024b9fa5d 2016-01-23 kinaba: #include <stack> 2024b9fa5d 2016-01-23 kinaba: #include <cmath> 2024b9fa5d 2016-01-23 kinaba: #include <cassert> 2024b9fa5d 2016-01-23 kinaba: #include <tuple> 2024b9fa5d 2016-01-23 kinaba: using namespace std; 2024b9fa5d 2016-01-23 kinaba: typedef long long LL; 2024b9fa5d 2016-01-23 kinaba: typedef complex<double> CMP; 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: static const int MODVAL = 1000000007; 2024b9fa5d 2016-01-23 kinaba: class BagAndCards { public: 2024b9fa5d 2016-01-23 kinaba: int getHash(int n, int m, int x, int a, int b, int c, string isGood) 2024b9fa5d 2016-01-23 kinaba: { 2024b9fa5d 2016-01-23 kinaba: vector<vector<int>> count(n, vector<int>(m, 0)); 2024b9fa5d 2016-01-23 kinaba: for(int i=0; i<n; ++i) 2024b9fa5d 2016-01-23 kinaba: for(int j=0; j<m; ++j) { 2024b9fa5d 2016-01-23 kinaba: count[i][j] = x; 2024b9fa5d 2016-01-23 kinaba: x = int(((LL(x) * a + b) ^ c) % MODVAL); 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: int total_ans = 0; 2024b9fa5d 2016-01-23 kinaba: for(int i=0; i<n; ++i) 2024b9fa5d 2016-01-23 kinaba: { 2024b9fa5d 2016-01-23 kinaba: vector<LL> mult(m); 2024b9fa5d 2016-01-23 kinaba: for(int c1=0; c1<m; ++c1) 2024b9fa5d 2016-01-23 kinaba: for(int c2=0; c2<m; ++c2) 2024b9fa5d 2016-01-23 kinaba: if(isGood[c1+c2]=='Y') 2024b9fa5d 2016-01-23 kinaba: mult[c2] += count[i][c1]; 2024b9fa5d 2016-01-23 kinaba: for(int c=0; c<m; ++c) 2024b9fa5d 2016-01-23 kinaba: mult[c] %= MODVAL; 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: for(int k=i+1; k<n; ++k) 2024b9fa5d 2016-01-23 kinaba: { 2024b9fa5d 2016-01-23 kinaba: LL ans = 0; 2024b9fa5d 2016-01-23 kinaba: for(int c=0; c<m; ++c) 2024b9fa5d 2016-01-23 kinaba: ans += count[k][c] * mult[c] % MODVAL; 2024b9fa5d 2016-01-23 kinaba: total_ans ^= int(ans % MODVAL); 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: return total_ans; 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: }; 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: // BEGIN CUT HERE 2024b9fa5d 2016-01-23 kinaba: #include <ctime> 2024b9fa5d 2016-01-23 kinaba: double start_time; string timer() 2024b9fa5d 2016-01-23 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 2024b9fa5d 2016-01-23 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 2024b9fa5d 2016-01-23 kinaba: { os << "{ "; 2024b9fa5d 2016-01-23 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 2024b9fa5d 2016-01-23 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 2024b9fa5d 2016-01-23 kinaba: void verify_case(const int& Expected, const int& Received) { 2024b9fa5d 2016-01-23 kinaba: bool ok = (Expected == Received); 2024b9fa5d 2016-01-23 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 2024b9fa5d 2016-01-23 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 2024b9fa5d 2016-01-23 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 2024b9fa5d 2016-01-23 kinaba: #define END verify_case(_, BagAndCards().getHash(n, m, x, a, b, c, isGood));} 2024b9fa5d 2016-01-23 kinaba: int main(){ 2024b9fa5d 2016-01-23 kinaba: 2024b9fa5d 2016-01-23 kinaba: CASE(0) 2024b9fa5d 2016-01-23 kinaba: int n = 2; 2024b9fa5d 2016-01-23 kinaba: int m = 4; 2024b9fa5d 2016-01-23 kinaba: int x = 1; 2024b9fa5d 2016-01-23 kinaba: int a = 1; 2024b9fa5d 2016-01-23 kinaba: int b = 0; 2024b9fa5d 2016-01-23 kinaba: int c = 0; 2024b9fa5d 2016-01-23 kinaba: string isGood = "NNYYNYN"; 2024b9fa5d 2016-01-23 kinaba: int _ = 9; 2024b9fa5d 2016-01-23 kinaba: END 2024b9fa5d 2016-01-23 kinaba: CASE(1) 2024b9fa5d 2016-01-23 kinaba: int n = 3; 2024b9fa5d 2016-01-23 kinaba: int m = 5; 2024b9fa5d 2016-01-23 kinaba: int x = 1; 2024b9fa5d 2016-01-23 kinaba: int a = 1; 2024b9fa5d 2016-01-23 kinaba: int b = 1; 2024b9fa5d 2016-01-23 kinaba: int c = 2; 2024b9fa5d 2016-01-23 kinaba: string isGood = "NNYYNYNYN"; 2024b9fa5d 2016-01-23 kinaba: int _ = 1532; 2024b9fa5d 2016-01-23 kinaba: END 2024b9fa5d 2016-01-23 kinaba: CASE(2) 2024b9fa5d 2016-01-23 kinaba: int n = 10; 2024b9fa5d 2016-01-23 kinaba: int m = 20; 2024b9fa5d 2016-01-23 kinaba: int x = 111; 2024b9fa5d 2016-01-23 kinaba: int a = 222; 2024b9fa5d 2016-01-23 kinaba: int b = 333; 2024b9fa5d 2016-01-23 kinaba: int c = 444; 2024b9fa5d 2016-01-23 kinaba: string isGood = "NNNNNYYYNNNYYYYYYNNYYYYNNNNYNNYYYNNNYYN" ; 2024b9fa5d 2016-01-23 kinaba: int _ = 450750683; 2024b9fa5d 2016-01-23 kinaba: END 2024b9fa5d 2016-01-23 kinaba: CASE(3) 2024b9fa5d 2016-01-23 kinaba: int n = 2; 2024b9fa5d 2016-01-23 kinaba: int m = 2; 2024b9fa5d 2016-01-23 kinaba: int x = 1; 2024b9fa5d 2016-01-23 kinaba: int a = 1; 2024b9fa5d 2016-01-23 kinaba: int b = 0; 2024b9fa5d 2016-01-23 kinaba: int c = 0; 2024b9fa5d 2016-01-23 kinaba: string isGood = "NNY"; 2024b9fa5d 2016-01-23 kinaba: int _ = 1; 2024b9fa5d 2016-01-23 kinaba: END 2024b9fa5d 2016-01-23 kinaba: /* 2024b9fa5d 2016-01-23 kinaba: CASE(4) 2024b9fa5d 2016-01-23 kinaba: int n = ; 2024b9fa5d 2016-01-23 kinaba: int m = ; 2024b9fa5d 2016-01-23 kinaba: int x = ; 2024b9fa5d 2016-01-23 kinaba: int a = ; 2024b9fa5d 2016-01-23 kinaba: int b = ; 2024b9fa5d 2016-01-23 kinaba: int c = ; 2024b9fa5d 2016-01-23 kinaba: string isGood = ; 2024b9fa5d 2016-01-23 kinaba: int _ = ; 2024b9fa5d 2016-01-23 kinaba: END 2024b9fa5d 2016-01-23 kinaba: CASE(5) 2024b9fa5d 2016-01-23 kinaba: int n = ; 2024b9fa5d 2016-01-23 kinaba: int m = ; 2024b9fa5d 2016-01-23 kinaba: int x = ; 2024b9fa5d 2016-01-23 kinaba: int a = ; 2024b9fa5d 2016-01-23 kinaba: int b = ; 2024b9fa5d 2016-01-23 kinaba: int c = ; 2024b9fa5d 2016-01-23 kinaba: string isGood = ; 2024b9fa5d 2016-01-23 kinaba: int _ = ; 2024b9fa5d 2016-01-23 kinaba: END 2024b9fa5d 2016-01-23 kinaba: */ 2024b9fa5d 2016-01-23 kinaba: } 2024b9fa5d 2016-01-23 kinaba: // END CUT HERE