結果

問題 No.1421 国勢調査 (Hard)
ユーザー convexineqconvexineq
提出日時 2021-03-08 00:35:52
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 849 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,312 KB
最終ジャッジ日時 2024-04-17 16:42:59
合計ジャッジ時間 4,822 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
52,096 KB
testcase_01 AC 30 ms
51,968 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 32 ms
52,352 KB
testcase_13 AC 33 ms
52,608 KB
testcase_14 AC 32 ms
52,864 KB
testcase_15 AC 30 ms
52,352 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 32 ms
52,352 KB
testcase_20 AC 31 ms
52,608 KB
testcase_21 RE -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 97 ms
76,544 KB
testcase_28 AC 98 ms
76,416 KB
testcase_29 AC 94 ms
76,840 KB
testcase_30 AC 93 ms
76,672 KB
testcase_31 AC 96 ms
76,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve_linear_equation_F2_col(A,b):
    n = len(A)
    for i in range(n):
        idx = max(range(i,n),key=lambda x:A[x])
        if A[idx]==0:
            rank = i
            break
        if idx != i:
            A[i],A[idx] = A[idx],A[i]
            b[i],b[idx] = b[idx],b[i]
        for j in range(n):
            if i != j and A[j] > A[j]^A[i]:
                A[j] ^= A[i]
                b[j] ^= b[i]
    else:
        rank = n

    if any(Ai for Ai in range(rank,n)):
        return [-1]

    ans = [0]*n
    for i in range(rank):
        ans[A[i].bit_length()-1] = Y[i]
    return ans

n,m = map(int,input().split())
A = [0]*m
Y = [0]*m
for i in range(m):
    _ = int(input())
    *a, = map(int,input().split())
    for ai in a:
        A[i] |= 1<<(ai-1)
    Y[i] = int(input())

x = solve_linear_equation_F2_col(A,Y)
print(*x,sep="\n")
0