結果

問題 No.2658 L-R Nim
ユーザー sotanishysotanishy
提出日時 2024-03-02 00:14:09
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 690 ms / 7,000 ms
コード長 2,295 bytes
コンパイル時間 3,264 ms
コンパイル使用メモリ 259,312 KB
実行使用メモリ 10,452 KB
最終ジャッジ日時 2024-03-02 00:14:29
合計ジャッジ時間 19,767 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,416 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 3 ms
7,416 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 21 ms
8,036 KB
testcase_06 AC 5 ms
6,676 KB
testcase_07 AC 9 ms
8,024 KB
testcase_08 AC 35 ms
8,044 KB
testcase_09 AC 38 ms
8,032 KB
testcase_10 AC 5 ms
6,676 KB
testcase_11 AC 39 ms
8,044 KB
testcase_12 AC 5 ms
6,676 KB
testcase_13 AC 5 ms
6,676 KB
testcase_14 AC 5 ms
6,676 KB
testcase_15 AC 25 ms
8,044 KB
testcase_16 AC 5 ms
6,676 KB
testcase_17 AC 26 ms
8,024 KB
testcase_18 AC 21 ms
8,016 KB
testcase_19 AC 5 ms
6,676 KB
testcase_20 AC 22 ms
8,040 KB
testcase_21 AC 5 ms
6,676 KB
testcase_22 AC 5 ms
6,676 KB
testcase_23 AC 9 ms
8,024 KB
testcase_24 AC 25 ms
8,024 KB
testcase_25 AC 669 ms
10,452 KB
testcase_26 AC 338 ms
10,452 KB
testcase_27 AC 675 ms
10,452 KB
testcase_28 AC 648 ms
10,452 KB
testcase_29 AC 560 ms
10,452 KB
testcase_30 AC 368 ms
10,452 KB
testcase_31 AC 305 ms
10,452 KB
testcase_32 AC 680 ms
10,452 KB
testcase_33 AC 17 ms
6,676 KB
testcase_34 AC 66 ms
9,224 KB
testcase_35 AC 401 ms
9,340 KB
testcase_36 AC 128 ms
10,408 KB
testcase_37 AC 20 ms
6,676 KB
testcase_38 AC 644 ms
10,452 KB
testcase_39 AC 628 ms
10,452 KB
testcase_40 AC 669 ms
10,452 KB
testcase_41 AC 674 ms
10,452 KB
testcase_42 AC 668 ms
10,452 KB
testcase_43 AC 663 ms
10,452 KB
testcase_44 AC 603 ms
10,452 KB
testcase_45 AC 639 ms
10,452 KB
testcase_46 AC 642 ms
10,452 KB
testcase_47 AC 648 ms
10,452 KB
testcase_48 AC 77 ms
10,400 KB
testcase_49 AC 560 ms
10,452 KB
testcase_50 AC 605 ms
10,452 KB
testcase_51 AC 666 ms
10,452 KB
testcase_52 AC 690 ms
10,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T>
bool chmax(T& a, const T& b) {
    return a < b ? (a = b, 1) : 0;
}
template <typename T>
bool chmin(T& a, const T& b) {
    return a > b ? (a = b, 1) : 0;
}

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i];
        if (i < (int)v.size() - 1) os << " ";
    }
    return os;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (auto& x : A) cin >> x;
    vector<int> B(N + 1);
    rep(i, 0, N) B[i + 1] = B[i] ^ A[i];
    map<int, int> prv;
    int left = 0;
    int right = N;
    bool f = false;
    rep(i, 0, N + 1) {
        if (prv.contains(B[i])) {
            if (prv[B[i]] == -1) {
                cout << "No" << endl;
                return 0;
            }
            chmax(left, prv[B[i]]);
            chmin(right, i);
            prv[B[i]] = -1;
            f = true;
        } else {
            prv[B[i]] = i;
        }
    }
    if (left >= right) {
        cout << "No" << endl;
        return 0;
    }
    if (!f) {
        cout << "Yes" << endl;
        return 0;
    }

    set<int> cand;
    rep(i, left, right) {
        rep(x, max(1, A[i] - K), A[i] + K + 1) cand.insert(x ^ A[i]);
    }

    vector<int> first(1 << 20, -1);
    rep(i, 0, N + 1) {
        if (first[B[i]] == -1) {
            first[B[i]] = i;
        }
    }

    for (int x : cand) {
        vector<int> banned(N + 1);
        rep(i, 0, N + 1) {
            if (first[B[i] ^ x] != -1) {
                int l = first[B[i] ^ x];
                if (l < i) {
                    ++banned[l];
                    --banned[i];
                }
            }
        }
        rep(i, 0, N) banned[i + 1] += banned[i];
        rep(i, left, right) {
            if (!banned[i] && abs((A[i] ^ x) - A[i]) <= K) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}
0