結果
| 問題 | No.2672 Subset Xor Sum |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-01-08 04:01:57 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 1,332 ms / 2,000 ms |
| コード長 | 1,325 bytes |
| 記録 | |
| コンパイル時間 | 393 ms |
| コンパイル使用メモリ | 82,408 KB |
| 実行使用メモリ | 145,076 KB |
| 最終ジャッジ日時 | 2026-01-08 04:02:09 |
| 合計ジャッジ時間 | 8,472 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 66 |
ソースコード
from itertools import accumulate
from collections.abc import Iterable
def accum_dp(xs: Iterable, f, op, e, init: dict, *, is_reset=True):
dp = init.copy()
for x in xs:
pp = {} if is_reset else dp.copy()
dp, pp = pp, dp
for fm_key, fm_val in pp.items():
for to_key, to_val in f(fm_key, fm_val, x):
dp[to_key] = op(dp.get(to_key, e), to_val)
return dp
def accum_dp1(xs: Iterable, f, op, e, size: int, init: dict, *, is_reset=True):
dp = [e] * size
for k, v in init.items():
dp[k] = v
for x in xs:
pp = [e] * size if is_reset else dp.copy()
dp, pp = pp, dp
for i in range(size):
for p, v in f(i, pp[i], x):
if 0 <= p < size:
dp[p] = op(dp[p], v)
return dp
def f(k, v, x):
return [(k, v), (k ^ x, v + 1)]
# yield k, v
# yield k ^ x, v + 1
def op(a, b):
return min(a, b)
def solve():
s = 0
for a in A:
s ^= a
if s != 0: return False
if N > 5001: return True
if A.count(0) > 0: return True
init = {A[0]: 1}
dp = accum_dp1(A[1:], f, op, INF, 8200, init)
return dp[0] < N
INF = 1 << 62
N = int(input())
A = list(map(int, input().split()))
ans = solve()
if ans:
print('Yes')
else:
print('No')
norioc