QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#667374#56. Nim Productxx_mmc75 1ms3960kbC++171.4kb2024-10-22 22:34:272024-10-22 22:34:37

Judging History

你现在查看的是最新测评结果

  • [2024-10-22 22:34:37]
  • 评测
  • 测评结果:75
  • 用时:1ms
  • 内存:3960kb
  • [2024-10-22 22:34:27]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

namespace NIM
{
    using uint = unsigned int;
    const uint N = 1 << 8;

    uint rem[N][N];
    bool vis[N][N];
    void init() {
        memset(vis, 0, sizeof vis);
    }
    uint nimP(uint x, uint y, int k = 16) {
        if (x <= 1 || y <= 1) return x * y;
        if (k < 8 && vis[x][y]) return rem[x][y];
        uint a = x >> k, b = y >> k, c = x & ((1ull << k) - 1), d = y & ((1ull << k) - 1);
        uint ab = nimP(1ull << k >> 1, nimP(a, b, k >> 1), k >> 1);
        uint cd = nimP(c, d, k >> 1);
        uint res = ((nimP(a ^ c, b ^ d, k >> 1) ^ cd) << k) ^ ab ^ cd;
        if (k < 8) {
            rem[x][y] = res;
            vis[x][y] = 1;
        }
        return res;
    }
};

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();
        lastans = NIM::nimP(x, y);
    }
    cout << lastans << endl;
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

详细


Pretests


Final Tests

Test #1:

score: 25
Accepted
time: 1ms
memory: 3896kb

input:

10 274134852 279286565 744539633

output:

2002382043

result:

ok single line: '2002382043'

Test #2:

score: 25
Accepted
time: 1ms
memory: 3944kb

input:

1000 734766235 309378503 610268282

output:

2106551671

result:

ok single line: '2106551671'

Test #3:

score: 25
Accepted
time: 0ms
memory: 3960kb

input:

30000 784936363 827067061 800454511

output:

554318281

result:

ok single line: '554318281'

Test #4:

score: 0
Time Limit Exceeded

input:

30000000 72129929 485897764 129463885

output:


result: