結果
| 問題 |
No.74 貯金箱の退屈
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 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 sys
n = 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 effect
matrix = []
for i in range(n):
effect = [0] * n
j = (i + D[i]) % n
k = (i - D[i]) % n
if j == k:
effect[j] ^= 1
else:
effect[j] ^= 1
effect[k] ^= 1
matrix.append(effect)
# Gaussian elimination over GF(2) to check if solution exists
# Build augmented matrix
aug = []
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 i
row.append(b[i])
aug.append(row)
rank = 0
for col in range(n):
pivot = -1
for row in range(rank, n):
if aug[row][col] == 1:
pivot = row
break
if pivot == -1:
continue
aug[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 += 1
for row in range(rank, n):
if aug[row][-1] == 1:
print("No")
return
print("Yes")
solve()
lam6er