結果

問題 No.2658 L-R Nim
ユーザー SnowBeenDidingSnowBeenDiding
提出日時 2024-03-01 22:54:18
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,413 bytes
コンパイル時間 5,072 ms
コンパイル使用メモリ 316,432 KB
実行使用メモリ 15,172 KB
最終ジャッジ日時 2024-09-29 14:42:45
合計ジャッジ時間 15,550 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 12 WA * 8 TLE * 1 -- * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace std;
using namespace atcoder;

typedef long long ll;

int f(vector<int> a) {
    int n = a.size();
    map<int, int> ma;
    int x = 0;
    ma[0]++;
    rep(i, 0, n) {
        x ^= a[i];
        ma[x]++;
    }
    x = 0;
    int ct = 0;
    rep(i, 0, n) {
        ma[x]--;
        ct += ma[x];
        x ^= a[i];
    }
    return ct;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    map<int, int> ma;
    int x = 0;
    ma[0]++;
    rep(i, 0, n) {
        x ^= a[i];
        ma[x]++;
    }
    x = 0;
    int l = 0;
    int ct = 0;
    rep(i, 0, n) {
        ma[x]--;
        ct += ma[x];
        if (ma[x]) l = i;
        x ^= a[i];
    }
    if (ct >= 2) {
        cout << "No" << endl;
        return 0;
    }
    if (ct == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    int r = l;
    x = a[l];
    while (x != 0) {
        r++;
        x ^= a[r];
    }
    rep(i, -k, +k + 1) {
        a[l] += i;
        int ct = f(a);
        if (ct == 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a[l] -= i;
        a[r] += i;
        ct = f(a);
        if (ct == 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a[r] -= i;
    }
    cout << "No" << endl;
}
0