QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#667296 | #56. Nim Product | xx_mmc | 75 | 32ms | 3608kb | C++17 | 1.7kb | 2024-10-22 22:04:59 | 2024-10-22 22:05:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
namespace NIM {
static unsigned int f[32][32]; // must be initialized to -1
void init() {
memset(f, -1, sizeof f);
}
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;
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);
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;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 25
Accepted
time: 1ms
memory: 3608kb
input:
10 274134852 279286565 744539633
output:
2002382043
result:
ok single line: '2002382043'
Test #2:
score: 25
Accepted
time: 2ms
memory: 3516kb
input:
1000 734766235 309378503 610268282
output:
2106551671
result:
ok single line: '2106551671'
Test #3:
score: 25
Accepted
time: 32ms
memory: 3512kb
input:
30000 784936363 827067061 800454511
output:
554318281
result:
ok single line: '554318281'
Test #4:
score: 0
Time Limit Exceeded
input:
30000000 72129929 485897764 129463885