結果
| 問題 |
No.2672 Subset Xor Sum
|
| コンテスト | |
| ユーザー |
Today03
|
| 提出日時 | 2024-03-16 11:39:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 150 ms / 2,000 ms |
| コード長 | 1,154 bytes |
| コンパイル時間 | 1,887 ms |
| コンパイル使用メモリ | 198,188 KB |
| 最終ジャッジ日時 | 2025-02-20 06:46:28 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 66 |
ソースコード
#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 << 13;
vector<vector<int>> dp(2, vector<int>(mx, false));
dp[1][A[0]] = true;
for (int i = 0; i < N - 1; i++) {
vector<vector<int>> ndp(2, vector<int>(mx, false));
for (int k = 0; k < 2; k++) {
for (int j = 0; j < mx; j++) {
if (dp[k][j]) {
ndp[0][j] = true;
if ((j ^ A[i + 1]) <= mx) {
ndp[k][j ^ A[i + 1]] = true;
}
}
}
}
swap(dp, ndp);
}
if (dp[0][0]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
Today03