QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#667325 | #56. Nim Product | xx_mmc | 75 | 40ms | 7804kb | C++17 | 1.9kb | 2024-10-22 22:11:28 | 2024-10-22 22:11:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
namespace NIM {
static unsigned int f[32][32]; // must be initialized to -1
static unsigned int g[1024][1024]; // must be initialized to -1
void init() {
memset(f, -1, sizeof f);
memset(g, -1, sizeof g);
}
unsigned int nim_mul(unsigned int x, unsigned int y);
unsigned int nim_mul_2power(unsigned int x, unsigned int y){
if (!x || !y) return 1 << (x + y);
unsigned int &F = f[x][y];
if (F != -1) return F;
unsigned int ret = 1, tmp = 1;
for(int i = 0; i < 6; ++i)
if ((x ^ y) >> i & 1) tmp *= 1 << (1 << i);
else if (x >> i & 1) ret = nim_mul(ret, 3 * (1 << ((1 << i) - 1)));
return F = nim_mul(ret, tmp);
}
unsigned int nim_mul(unsigned int x, unsigned int y){
if (x < 2 || y < 2) return x * y;
if (x < 1024u && y < 1024u && g[x][y] != -1) return g[x][y];
unsigned int ret = 0;
for(int i = 0; i < 32; ++i)
if (x >> i & 1)
for(int j = 0; j < 32; ++j)
if (y >> j & 1)
ret ^= nim_mul_2power(i, j);
if (x < 1024u && y < 1024u) g[x][y] = ret;
return ret;
}
};
unsigned int SA, SB, SC;
unsigned int rng() {
SA ^= SA << 16;
SA ^= SA >> 5;
SA ^= SA << 1;
unsigned int t = SA;
SA = SB;
SB = SC;
SC ^= t ^ SA;
return SC;
}
void solve() {
int T;
cin >> T >> SA >> SB >> SC;
unsigned int lastans = 0;
NIM::init();
while (T--) {
unsigned int x = rng() + lastans;
unsigned int y = rng();
// cout << x << " " << y << endl;
lastans = NIM::nim_mul(x, y);
if (!T) cout << lastans << endl;
}
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T = 1;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 25
Accepted
time: 0ms
memory: 7744kb
input:
10 274134852 279286565 744539633
output:
2002382043
result:
ok single line: '2002382043'
Test #2:
score: 25
Accepted
time: 3ms
memory: 7804kb
input:
1000 734766235 309378503 610268282
output:
2106551671
result:
ok single line: '2106551671'
Test #3:
score: 25
Accepted
time: 40ms
memory: 7708kb
input:
30000 784936363 827067061 800454511
output:
554318281
result:
ok single line: '554318281'
Test #4:
score: 0
Time Limit Exceeded
input:
30000000 72129929 485897764 129463885