結果

問題 No.1421 国勢調査 (Hard)
ユーザー vwxyzvwxyz
提出日時 2023-05-24 20:32:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 1,173 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 9,408 KB
最終ジャッジ日時 2023-08-25 13:06:34
合計ジャッジ時間 5,008 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,236 KB
testcase_01 AC 14 ms
8,204 KB
testcase_02 AC 13 ms
8,144 KB
testcase_03 AC 13 ms
8,252 KB
testcase_04 AC 15 ms
8,144 KB
testcase_05 AC 15 ms
8,216 KB
testcase_06 AC 15 ms
8,268 KB
testcase_07 AC 15 ms
8,232 KB
testcase_08 AC 15 ms
8,268 KB
testcase_09 AC 14 ms
8,248 KB
testcase_10 AC 15 ms
8,244 KB
testcase_11 AC 15 ms
8,240 KB
testcase_12 AC 16 ms
8,244 KB
testcase_13 AC 15 ms
8,216 KB
testcase_14 AC 14 ms
8,244 KB
testcase_15 AC 14 ms
8,252 KB
testcase_16 AC 13 ms
8,328 KB
testcase_17 AC 13 ms
8,248 KB
testcase_18 AC 14 ms
8,292 KB
testcase_19 AC 13 ms
8,348 KB
testcase_20 AC 14 ms
8,160 KB
testcase_21 AC 14 ms
8,164 KB
testcase_22 AC 286 ms
9,096 KB
testcase_23 AC 285 ms
9,172 KB
testcase_24 AC 304 ms
9,116 KB
testcase_25 AC 288 ms
9,072 KB
testcase_26 AC 320 ms
9,216 KB
testcase_27 AC 310 ms
9,408 KB
testcase_28 AC 228 ms
9,088 KB
testcase_29 AC 217 ms
9,400 KB
testcase_30 AC 144 ms
9,212 KB
testcase_31 AC 123 ms
9,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

def XOR_Basis(lst):
    xor_basis=[]
    triangulation=[]
    for i,x in enumerate(lst):
        xx=x
        for j,xb in enumerate(triangulation):
            if xx>xx^xb:
                xx=xx^xb
        if xx:
            xor_basis.append(x)
            for j in range(len(triangulation)):
                if triangulation[j]^xx<triangulation[j]:
                    triangulation[j]^=xx
            triangulation.append(xx)
    return xor_basis,triangulation

N,M=map(int,readline().split())
A,B,Y=[],[],[]
for m in range(M):
    A.append(int(readline()))
    B.append(sum(1<<b-1 for b in map(int,readline().split())))
    Y.append(int(readline()))
ans_lst=[0]*N
xor_basis=[]
tria=[]
tria_Y=[]
for b,y in zip(B,Y):
    for xb,xby in zip(tria,tria_Y):
        if b>b^xb:
            b=b^xb
            y^=xby
    if b:
        for j in range(len(tria)):
            if tria[j]^b<tria[j]:
                tria[j]^=b
                tria_Y[j]^=y
        tria.append(b)
        tria_Y.append(y)
    elif y:
        print(-1)
        exit()
    for b,y in zip(tria,tria_Y):
        ans_lst[b.bit_length()-1]=y
print(*ans_lst,sep="\n")
0