結果

問題 No.2658 L-R Nim
ユーザー てんぷらてんぷら
提出日時 2024-02-29 01:51:08
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 637 ms / 7,000 ms
コード長 2,131 bytes
コンパイル時間 5,306 ms
コンパイル使用メモリ 310,136 KB
実行使用メモリ 20,132 KB
最終ジャッジ日時 2024-02-29 02:35:27
合計ジャッジ時間 21,508 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
19,728 KB
testcase_01 AC 6 ms
11,516 KB
testcase_02 AC 9 ms
19,728 KB
testcase_03 AC 6 ms
11,516 KB
testcase_04 AC 6 ms
11,516 KB
testcase_05 AC 71 ms
19,796 KB
testcase_06 AC 6 ms
11,584 KB
testcase_07 AC 71 ms
19,796 KB
testcase_08 AC 72 ms
19,796 KB
testcase_09 AC 71 ms
19,796 KB
testcase_10 AC 7 ms
11,584 KB
testcase_11 AC 70 ms
19,796 KB
testcase_12 AC 7 ms
11,584 KB
testcase_13 AC 7 ms
11,584 KB
testcase_14 AC 6 ms
11,584 KB
testcase_15 AC 72 ms
19,796 KB
testcase_16 AC 7 ms
11,584 KB
testcase_17 AC 71 ms
19,796 KB
testcase_18 AC 70 ms
19,796 KB
testcase_19 AC 7 ms
11,584 KB
testcase_20 AC 71 ms
19,796 KB
testcase_21 AC 7 ms
11,584 KB
testcase_22 AC 7 ms
11,584 KB
testcase_23 AC 72 ms
19,796 KB
testcase_24 AC 71 ms
19,796 KB
testcase_25 AC 533 ms
20,132 KB
testcase_26 AC 534 ms
20,132 KB
testcase_27 AC 537 ms
20,132 KB
testcase_28 AC 545 ms
20,132 KB
testcase_29 AC 537 ms
20,132 KB
testcase_30 AC 534 ms
20,132 KB
testcase_31 AC 536 ms
20,132 KB
testcase_32 AC 537 ms
20,132 KB
testcase_33 AC 10 ms
11,756 KB
testcase_34 AC 218 ms
20,132 KB
testcase_35 AC 637 ms
19,984 KB
testcase_36 AC 515 ms
20,132 KB
testcase_37 AC 10 ms
11,840 KB
testcase_38 AC 532 ms
20,132 KB
testcase_39 AC 531 ms
20,132 KB
testcase_40 AC 538 ms
20,132 KB
testcase_41 AC 535 ms
20,132 KB
testcase_42 AC 536 ms
20,132 KB
testcase_43 AC 537 ms
20,132 KB
testcase_44 AC 566 ms
20,132 KB
testcase_45 AC 536 ms
20,132 KB
testcase_46 AC 542 ms
20,132 KB
testcase_47 AC 536 ms
20,132 KB
testcase_48 AC 523 ms
20,132 KB
testcase_49 AC 534 ms
20,132 KB
testcase_50 AC 532 ms
20,132 KB
testcase_51 AC 533 ms
20,132 KB
testcase_52 AC 534 ms
20,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
using namespace std;
using namespace atcoder;
using mint = modint998244353;
const int inf = 1000000007;
const ll longinf = 1ll << 60;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> s(n + 1);
    rep(i, n) s[i + 1] = s[i] ^ a[i];
    int m = 1 << 20;
    vector<int> l(m, -1), r(m, -1);
    int left = -1, right = n + 1;
    rep(i, n + 1) {
        if(r[s[i]] != -1) {
            left = max(left, r[s[i]]);
            right = min(right, i);
        }
        r[s[i]] = i;
        if(l[s[i]] == -1) {
            l[s[i]] = i;
        }
    }
    if(left >= right) {
        cout << "No" << endl;
        return 0;
    }
    if(left == -1) {
        cout << "Yes" << endl;
        return 0;
    }
    vector ng(128, vector(14, int(0)));
    bool can = false;
    vector<pair<int, int>> p(1 << 20);
    rep(j, 128) rep(k, 14) {
        int v = j | ((1 << k) - 1) << 7;
        p[v] = {j, k};
    }
    rep(i, n) {
        if(l[s[i]] == i) {
            rep(j, 128) rep(k, 14) {
                int v = j | ((1 << k) - 1) << 7;
                int ri = r[s[i] ^ v];
                if(ri != -1 && i < ri) {
                    ++ng[j][k];
                }
            }
        }
        if(r[s[i]] == i) {
            rep(j, 128) rep(k, 14) {
                int v = j | ((1 << k) - 1) << 7;
                int li = l[s[i] ^ v];
                if(li != -1 && li < i) {
                    --ng[j][k];
                }
            }
        }
        if(left <= i && i < right) {
            for(int j = max(1, a[i] - k); j <= a[i] + k; j++) {
                auto [v, c] = p[j ^ a[i]];
                if(!ng[v][c]) {
                    can = true;
                    break;
                }
            }
        }
    }
    cout << (can ? "Yes" : "No") << endl;
    return 0;
}
0