結果
| 問題 | No.74 貯金箱の退屈 |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:22:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 5,000 ms |
| コード長 | 1,339 bytes |
| コンパイル時間 | 174 ms |
| コンパイル使用メモリ | 82,040 KB |
| 実行使用メモリ | 62,208 KB |
| 最終ジャッジ日時 | 2025-03-31 17:23:19 |
| 合計ジャッジ時間 | 2,936 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
n = int(input())
D = list(map(int, input().split()))
W = list(map(int, input().split()))
b = [(1 - w) % 2 for w in W]
# Initialize the matrix
matrix = [[0] * n for _ in range(n)]
for j in range(n):
dj = D[j]
a = (j + dj) % n
b_pos = (j - dj) % n
if a == b_pos:
matrix[a][j] ^= 1
else:
matrix[a][j] ^= 1
matrix[b_pos][j] ^= 1
# Create augmented matrix
augmented = []
for i in range(n):
row = matrix[i].copy()
row.append(b[i])
augmented.append(row)
def gauss_jordan(augmented, n_vars):
rank = 0
n_rows = len(augmented)
for col in range(n_vars):
pivot = None
for row in range(rank, n_rows):
if augmented[row][col] == 1:
pivot = row
break
if pivot is None:
continue
augmented[rank], augmented[pivot] = augmented[pivot], augmented[rank]
for row in range(n_rows):
if row != rank and augmented[row][col] == 1:
for c in range(col, n_vars + 1):
augmented[row][c] ^= augmented[rank][c]
rank += 1
# Check for contradictions
for row in augmented:
if all(x == 0 for x in row[:-1]) and row[-1] == 1:
return False
return True
possible = gauss_jordan(augmented, n)
print("Yes" if possible else "No")
lam6er