結果
問題 |
No.1421 国勢調査 (Hard)
|
ユーザー |
👑 |
提出日時 | 2024-03-20 22:57:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 349 ms / 2,000 ms |
コード長 | 1,108 bytes |
コンパイル時間 | 335 ms |
コンパイル使用メモリ | 82,248 KB |
実行使用メモリ | 77,372 KB |
最終ジャッジ日時 | 2024-09-30 09:05:10 |
合計ジャッジ時間 | 5,871 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
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")