結果

問題 No.1421 国勢調査 (Hard)
ユーザー 👑 rin204rin204
提出日時 2024-03-20 22:57:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 428 ms / 2,000 ms
コード長 1,108 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,840 KB
最終ジャッジ日時 2024-03-20 22:57:55
合計ジャッジ時間 7,083 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 64 ms
68,748 KB
testcase_03 AC 65 ms
68,748 KB
testcase_04 AC 64 ms
68,760 KB
testcase_05 AC 64 ms
68,748 KB
testcase_06 AC 64 ms
68,740 KB
testcase_07 AC 64 ms
68,752 KB
testcase_08 AC 65 ms
68,748 KB
testcase_09 AC 66 ms
68,748 KB
testcase_10 AC 64 ms
68,748 KB
testcase_11 AC 67 ms
68,748 KB
testcase_12 AC 40 ms
53,460 KB
testcase_13 AC 39 ms
53,460 KB
testcase_14 AC 40 ms
53,460 KB
testcase_15 AC 39 ms
53,460 KB
testcase_16 AC 63 ms
68,748 KB
testcase_17 AC 61 ms
68,740 KB
testcase_18 AC 62 ms
68,752 KB
testcase_19 AC 46 ms
59,700 KB
testcase_20 AC 42 ms
53,460 KB
testcase_21 AC 62 ms
68,744 KB
testcase_22 AC 389 ms
76,840 KB
testcase_23 AC 391 ms
76,836 KB
testcase_24 AC 428 ms
76,840 KB
testcase_25 AC 387 ms
76,708 KB
testcase_26 AC 395 ms
76,712 KB
testcase_27 AC 117 ms
76,196 KB
testcase_28 AC 154 ms
76,580 KB
testcase_29 AC 131 ms
76,580 KB
testcase_30 AC 107 ms
76,196 KB
testcase_31 AC 125 ms
76,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
X = []
Y = []
for _ in range(m):
    a = int(input())
    B = list(map(int, input().split()))
    y = int(input())
    bits = 0
    for b in B:
        bits |= 1 << (b - 1)
    X.append(bits)
    Y.append(y)

ans = [0] * n
for i in range(30):
    base = []
    oz = []
    for x, y in zip(X, Y):
        z = (y >> i) & 1
        for b, o in zip(base, oz):
            if x ^ b < x:
                x ^= b
                z ^= o

        if x == 0:
            if z:
                print(-1)
                exit()
        else:
            base.append(x)
            oz.append(z)
            for j in range(len(base) - 1, 0, -1):
                if base[j] > base[j - 1]:
                    base[j], base[j - 1] = base[j - 1], base[j]
                    oz[j], oz[j - 1] = oz[j - 1], oz[j]

    for b, o in zip(base[::-1], oz[::-1]):
        inds = []
        for j in range(n):
            if b >> j & 1:
                inds.append(j)

        for j in inds[:-1]:
            o ^= ans[j] >> i & 1
        if o:
            ans[inds[-1]] |= 1 << i

print(*ans, sep="\n")
0