結果

問題 No.2672 Subset Xor Sum
ユーザー InTheBloom
提出日時 2024-03-15 21:47:24
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,108 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 99,580 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-09-30 00:44:26
合計ジャッジ時間 7,547 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 23 WA * 11 RE * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <vector>

using namespace std;

constexpr int iINF = 1'000'000'000;

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

    // 全体のxorが0という必要条件 -> 最初にチェックしておけば片側の存在を示せばOK
    // ダブり -> 即OK

    bool ok = true;
    int XOR = 0;

    for (auto a : A) XOR ^= a;

    if (XOR != 0) ok = false;

    map<int, int> mp;
    for (auto a : A) mp[a]++;

    const int MAX = 5000;
    vector<int> possible(MAX + 1, iINF);

    bool first = true;

    for (auto v : mp) {
        if (v.second % 2 == 0) break; // もうOK

        if (first) {
            first = false;
            possible[v.first] = 1;
            continue;
        }

        for (int i = 0; i <= MAX; i++) {
            if (!possible[i] == iINF) continue;
            possible[i ^ v.first] = min(possible[i ^ v.first], possible[i] + 1);
        }
    }

    if (N <= possible[0]) ok = false;

    if (ok) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}
0