結果

問題 No.2895 Zero XOR Subset
ユーザー detteiuudetteiuu
提出日時 2024-09-21 00:48:18
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,026 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 82,328 KB
実行使用メモリ 306,260 KB
最終ジャッジ日時 2024-09-21 00:48:24
合計ジャッジ時間 4,501 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
62,220 KB
testcase_01 AC 41 ms
55,488 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
A = list(map(int, input().split()))

B = [[0]*60 for _ in range(N)]
for i in range(N):
    for j in range(60):
        if 1<<j & A[i]:
            B[i][59-j] = 1

row = 0
idx = list(range(N))
ans = []
G = [[] for _ in range(N)]
for j in range(60):
    pivot = row
    while pivot < N and B[pivot][j] == 0:
        pivot += 1
    if pivot == N:
        continue
    B[row], B[pivot] = B[pivot], B[row]
    idx[row], idx[pivot] = idx[pivot], idx[row]
    for i in range(row+1, N):
        if i != row and B[i][j] == 1:
            G[i].append(row)
            for k in range(60):
                B[i][k] ^= B[row][k]
    row += 1

if max(B[-1]) == 0:
    que = deque()
    que.append(i)
    ans = set([idx[-1]+1])
    while que:
        n = que.popleft()
        for v in G[n]:
            if idx[v]+1 in ans:
                ans.remove(idx[v]+1)
            else:
                ans.add(idx[v]+1)
            que.append(v)
    print(len(ans))
    print(*ans)
else:
    print(-1)
0