結果

問題 No.2672 Subset Xor Sum
ユーザー Today03
提出日時 2024-03-15 21:45:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,139 bytes
コンパイル時間 2,342 ms
コンパイル使用メモリ 203,224 KB
最終ジャッジ日時 2025-02-20 04:51:27
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 43 WA * 2 MLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include "./debug.cpp"
#else
#define debug(...)
#define print_line
#endif
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int xors = 0;
    for (int i = 0; i < N; i++) {
        xors ^= A[i];
    }

    if (xors != 0) {
        cout << "No" << endl;
        return 0;
    }

    if (N > 5000) {
        cout << "Yes" << endl;
        return 0;
    }

    int mx = 1 << 12;
    vector<vector<vector<bool>>> dp(N, vector<vector<bool>>(mx + 1, vector<bool>(2, false)));
    dp[0][A[0]][1] = true;
    for (int i = 0; i < N - 1; i++) {
        for (int j = 0; j <= mx; j++) {
            for (int k = 0; k < 2; k++) {
                if (dp[i][j][k]) {
                    dp[i + 1][j][0] = true;
                    if ((j ^ A[i + 1]) <= mx) {
                        dp[i + 1][j ^ A[i + 1]][k] = true;
                    }
                }
            }
        }
    }

    if (dp[N - 1][0][0]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
0