結果

問題 No.2672 Subset Xor Sum
コンテスト
ユーザー norioc
提出日時 2026-01-08 03:47:39
言語 PyPy3
(7.3.17)
結果
WA  
実行時間 -
コード長 899 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 352 ms
コンパイル使用メモリ 82,772 KB
実行使用メモリ 268,648 KB
最終ジャッジ日時 2026-01-08 03:47:52
合計ジャッジ時間 11,389 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 55 WA * 5 TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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 f(k, v, x):
    yield k, v
    yield k ^ x, v + 1


def op(a, b):
    return min(a, b)


def solve():
    if N > 5001: return True

    s = 0
    for a in A:
        s ^= a
    if s != 0: return False

    if A.count(0) > 0: return True

    init = {A[0]: 1}
    dp = accum_dp(A[1:], f, op, INF, init)
    res = dp.get(0, INF)
    return res < N


INF = 1 << 62
N = int(input())
A = list(map(int, input().split()))
ans = solve()
if ans:
    print('Yes')
else:
    print('No')
0