結果
| 問題 | No.74 貯金箱の退屈 |
| コンテスト | |
| ユーザー |
ntuda
|
| 提出日時 | 2025-09-01 00:02:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 936 bytes |
| コンパイル時間 | 386 ms |
| コンパイル使用メモリ | 82,692 KB |
| 実行使用メモリ | 67,596 KB |
| 最終ジャッジ日時 | 2025-09-01 00:02:20 |
| 合計ジャッジ時間 | 3,555 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | AC * 18 RE * 12 |
ソースコード
N = int(input())
D = list(map(int, input().split()))
W = list(map(int, input().split()))
E = [set() for _ in range(N)]
for i in range(N):
d = D[i]
d = min(d % N, N - d % N)
a = (i - d) % N
b = (i + d) % N
E[a].add(b)
E[b].add(a)
D = [0] * N
Q = []
for i in range(N):
D[i] =len(E[i])
if D[i] == 0 and W[i] == 0:
print("No")
exit()
if D[i] == 1:
Q.append(i)
while Q:
x = Q.pop()
for y in E[x]:
if x == y:
W[x] = 1
continue
a = W[x] ^ 1
W[x] = 1
W[y] ^= a
E[y].remove(x)
D[y] -= 1
if D[y] == 1:
Q.append(y)
from atcoder.dsu import DSU
dsu = DSU(N)
for x in range(N):
for y in E[i]:
dsu.merge(x,y)
for G in dsu.groups():
cnt = 0
for g in G:
if W[g] == 0:
cnt += 1
if cnt % 2 == 1:
print("No")
exit()
print("Yes")
ntuda