結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,824 KB
testcase_01 AC 13 ms
8,152 KB
testcase_02 AC 13 ms
7,800 KB
testcase_03 AC 14 ms
7,896 KB
testcase_04 AC 14 ms
7,816 KB
testcase_05 AC 13 ms
7,752 KB
testcase_06 AC 14 ms
7,780 KB
testcase_07 AC 14 ms
7,900 KB
testcase_08 AC 14 ms
7,752 KB
testcase_09 AC 14 ms
7,828 KB
testcase_10 AC 14 ms
7,752 KB
testcase_11 AC 14 ms
7,900 KB
testcase_12 AC 14 ms
8,200 KB
testcase_13 AC 14 ms
8,148 KB
testcase_14 AC 14 ms
8,192 KB
testcase_15 AC 14 ms
8,080 KB
testcase_16 AC 14 ms
7,776 KB
testcase_17 AC 14 ms
7,728 KB
testcase_18 AC 14 ms
7,768 KB
testcase_19 AC 14 ms
8,260 KB
testcase_20 AC 13 ms
8,164 KB
testcase_21 AC 14 ms
7,828 KB
testcase_22 AC 277 ms
8,956 KB
testcase_23 AC 287 ms
9,040 KB
testcase_24 AC 291 ms
8,908 KB
testcase_25 AC 291 ms
8,956 KB
testcase_26 AC 282 ms
9,032 KB
testcase_27 AC 277 ms
8,900 KB
testcase_28 AC 228 ms
8,952 KB
testcase_29 AC 220 ms
8,936 KB
testcase_30 AC 145 ms
8,900 KB
testcase_31 AC 123 ms
8,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

N,M=map(int,readline().split())
B,Y=[],[]
for m in range(M):
    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