提出 #14943193


ソースコード 拡げる

#include <iostream>
#include <vector>
#include <algorithm>
using i64 = long long;

i64 memo[41][2];
i64 a, b, c, x;

i64 rec(const i64 i, const bool j) {
    if (i < 0) return 0;
    if (memo[i][j] != -2) return memo[i][j];
    const i64 mask = 1ll << i;
    const i64 p = mask & a, q = mask & x, r = mask & c;
    i64 ret;
    if (!q) {
        if (!r) {
            ret = rec(i - 1, j || p);
        } else {
            if (!p && !j) ret = -1;
            else if (const auto o = rec(i - 1, j); o >= 0) {
                ret = mask | o;
            } else {
                ret = -1;
            }
        }
    } else {
        if (!r) {
            const i64 z = rec(i - 1, j || p),
                o = !p && !j ? -1 : (rec(i - 1, j) >= 0 ? rec(i - 1, j) | mask : -1);
            ret = std::max(z, o);
        } else {
            ret = -1;
        }
    }

    return memo[i][j] = ret;
}

int main() {
    for (auto &v : memo) v[0] = v[1] = -2;
    int n;
    std::cin >> n >> a >> b;
    for (int i = 2; i < n; i++) {
        i64 in;
        std::cin >> in;
        x ^= in;
    }

    const i64 t = a + b - x;
    if (t < 0 || t % 2) {
        std::cout << -1 << std::endl;
        return 0;
    }

    c = t / 2;

    const i64 ret = rec(40, false);
    std::cout << (ret <= 0 ? -1 : a - ret) << std::endl;

    return 0;
}

提出情報

提出日時
問題 F - Unfair Nim
ユーザ CharlotteL
言語 C++ (GCC 9.2.1)
得点 600
コード長 1395 Byte
結果 AC
実行時間 6 ms
メモリ 3604 KiB

ジャッジ結果

セット名 Sample All after_contest
得点 / 配点 0 / 0 600 / 600 0 / 0
結果
AC × 5
AC × 23
AC × 1
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
All hand_01.txt, hand_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt, n2_01.txt, n2_02.txt, n2_03.txt, n2_04.txt, n3_01.txt, n3_02.txt, n3_03.txt, n3_04.txt
after_contest after_contest_01.txt
ケース名 結果 実行時間 メモリ
after_contest_01.txt AC 6 ms 3404 KiB
hand_01.txt AC 2 ms 3536 KiB
hand_02.txt AC 2 ms 3400 KiB
n2_01.txt AC 2 ms 3580 KiB
n2_02.txt AC 2 ms 3436 KiB
n2_03.txt AC 2 ms 3496 KiB
n2_04.txt AC 6 ms 3404 KiB
n3_01.txt AC 2 ms 3488 KiB
n3_02.txt AC 2 ms 3380 KiB
n3_03.txt AC 2 ms 3604 KiB
n3_04.txt AC 2 ms 3600 KiB
random_01.txt AC 2 ms 3376 KiB
random_02.txt AC 2 ms 3536 KiB
random_03.txt AC 2 ms 3380 KiB
random_04.txt AC 4 ms 3404 KiB
random_05.txt AC 2 ms 3500 KiB
random_06.txt AC 4 ms 3492 KiB
random_07.txt AC 2 ms 3512 KiB
random_08.txt AC 2 ms 3312 KiB
sample_01.txt AC 2 ms 3308 KiB
sample_02.txt AC 2 ms 3496 KiB
sample_03.txt AC 2 ms 3500 KiB
sample_04.txt AC 2 ms 3580 KiB
sample_05.txt AC 2 ms 3308 KiB