結果
問題 | No.74 貯金箱の退屈 |
ユーザー |
![]() |
提出日時 | 2022-11-07 12:50:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 44 ms / 5,000 ms |
コード長 | 1,039 bytes |
コンパイル時間 | 239 ms |
コンパイル使用メモリ | 82,312 KB |
実行使用メモリ | 52,864 KB |
最終ジャッジ日時 | 2024-07-20 21:02:06 |
合計ジャッジ時間 | 2,732 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
import sysinput=lambda:sys.stdin.readline().rstrip()class unionFind:def __init__(self,N):self.N=Nself.parent=[-1 for i in range(N)]self.size=[1 for i in range(N)]def find(self,x):path=[x]while self.parent[path[-1]]!=-1:path.append(self.parent[path[-1]])for i in path[:-1]:self.parent[i]=path[-1]return path[-1]def unite(self,x,y):roots=sorted([self.find(x),self.find(y)],key=lambda _:self.parent[_])if roots[0]!=roots[1]:self.parent[roots[0]]=roots[1]self.size[roots[1]]+=self.size[roots[0]]N=int(input())D=list(map(int,input().split()))W=list(map(int,input().split()))check=[0 for i in range(N)]U=unionFind(N)ans="Yes"mem={}for i in range(N):U.unite((i+D[i])%N,(i-D[i])%N)if 2*D[i]%N==0:check[i]=1for i in range(N):h=U.find(i)if not h in mem:mem[h]=[0,0]mem[h][0]^=(W[i]==0)mem[h][1]|=check[i]for i in mem:if mem[i][0] and mem[i][1]==0:ans="No"print(ans)