結果

問題 No.1421 国勢調査 (Hard)
ユーザー convexineqconvexineq
提出日時 2021-03-08 00:43:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 880 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,056 KB
最終ジャッジ日時 2024-04-17 16:49:16
合計ジャッジ時間 3,970 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,096 KB
testcase_01 AC 43 ms
51,968 KB
testcase_02 AC 43 ms
52,480 KB
testcase_03 AC 43 ms
52,224 KB
testcase_04 AC 43 ms
52,736 KB
testcase_05 AC 43 ms
52,480 KB
testcase_06 AC 46 ms
52,608 KB
testcase_07 AC 44 ms
52,352 KB
testcase_08 AC 44 ms
52,480 KB
testcase_09 AC 44 ms
52,736 KB
testcase_10 AC 44 ms
52,864 KB
testcase_11 AC 43 ms
52,096 KB
testcase_12 AC 44 ms
52,352 KB
testcase_13 AC 43 ms
52,224 KB
testcase_14 AC 43 ms
52,992 KB
testcase_15 AC 43 ms
52,224 KB
testcase_16 AC 44 ms
52,224 KB
testcase_17 AC 43 ms
52,608 KB
testcase_18 AC 44 ms
51,968 KB
testcase_19 AC 43 ms
52,608 KB
testcase_20 AC 43 ms
52,224 KB
testcase_21 AC 43 ms
52,736 KB
testcase_22 AC 132 ms
76,800 KB
testcase_23 AC 133 ms
76,928 KB
testcase_24 AC 132 ms
76,416 KB
testcase_25 AC 133 ms
76,672 KB
testcase_26 AC 130 ms
76,672 KB
testcase_27 AC 131 ms
76,800 KB
testcase_28 AC 130 ms
76,672 KB
testcase_29 AC 130 ms
76,416 KB
testcase_30 AC 133 ms
77,056 KB
testcase_31 AC 130 ms
76,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve_linear_equation_F2_col(A,b,m):
    assert len(A)==len(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(b[i] for i in range(rank,n)):
        return [-1]

    ans = [0]*m
    for i in range(rank):
        ans[A[i].bit_length()-1] = b[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,n)
print(*x,sep="\n")
0