結果
問題 | No.2672 Subset Xor Sum |
ユーザー |
![]() |
提出日時 | 2024-04-26 10:18:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 53 ms / 2,000 ms |
コード長 | 938 bytes |
コンパイル時間 | 400 ms |
コンパイル使用メモリ | 42,052 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-09 00:50:22 |
合計ジャッジ時間 | 3,809 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 66 |
ソースコード
/* -*- coding: utf-8 -*- * * 2672.cc: No.2672 Subset Xor Sum - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 500000; const int BN = 13; const int BBITS = 1 << BN; /* typedef */ /* global variables */ int as[MAX_N], cs[BBITS]; bool dp[BBITS]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); int sum = 0; for (int i = 0; i < n; i++) cs[as[i]]++, sum ^= as[i]; if (sum != 0 || (n == 2 && cs[0] == 0)) { puts("No"); return 0; } if (cs[0] > 0) { puts("Yes"); return 0; } for (int i = 1; i < BBITS; i++) if (cs[i] >= 2) { puts("Yes"); return 0; } dp[0] = true; for (int i = 0; i < n; i++) for (int j = BBITS - 1; j >= 0; j--) if (dp[j]) { int v = j ^ as[i]; dp[v] = true; if (v == 0 && i < n - 1) { puts("Yes"); return 0; } } puts("No"); return 0; }