結果
問題 | No.74 貯金箱の退屈 |
ユーザー |
![]() |
提出日時 | 2025-03-26 15:46:36 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 50 ms / 5,000 ms |
コード長 | 1,552 bytes |
コンパイル時間 | 285 ms |
コンパイル使用メモリ | 82,236 KB |
実行使用メモリ | 62,336 KB |
最終ジャッジ日時 | 2025-03-26 15:47:23 |
合計ジャッジ時間 | 2,985 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
def solve():import sysn = int(sys.stdin.readline())D = list(map(int, sys.stdin.readline().split()))W = list(map(int, sys.stdin.readline().split()))# Target vector: 1 where the coin needs to be flipped (W[i] == 0)b = [(1 - w) % 2 for w in W]# Create the effect matrix where each column is an operation's effectmatrix = []for i in range(n):effect = [0] * nj = (i + D[i]) % nk = (i - D[i]) % nif j == k:effect[j] ^= 1else:effect[j] ^= 1effect[k] ^= 1matrix.append(effect)# Gaussian elimination over GF(2) to check if solution exists# Build augmented matrixaug = []for i in range(n):row = []for j in range(n):row.append(matrix[j][i]) # matrix[j][i] is the effect of operation j on coin irow.append(b[i])aug.append(row)rank = 0for col in range(n):pivot = -1for row in range(rank, n):if aug[row][col] == 1:pivot = rowbreakif pivot == -1:continueaug[rank], aug[pivot] = aug[pivot], aug[rank]for row in range(n):if row != rank and aug[row][col] == 1:for c in range(col, n + 1):aug[row][c] ^= aug[rank][c]rank += 1for row in range(rank, n):if aug[row][-1] == 1:print("No")returnprint("Yes")solve()