結果
問題 | No.74 貯金箱の退屈 |
ユーザー | ytft |
提出日時 | 2022-11-07 12:50:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 67 ms / 5,000 ms |
コード長 | 1,039 bytes |
コンパイル時間 | 1,238 ms |
コンパイル使用メモリ | 86,880 KB |
実行使用メモリ | 71,440 KB |
最終ジャッジ日時 | 2023-09-28 02:25:11 |
合計ジャッジ時間 | 4,116 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 64 ms
71,064 KB |
testcase_01 | AC | 65 ms
71,176 KB |
testcase_02 | AC | 67 ms
71,060 KB |
testcase_03 | AC | 65 ms
71,056 KB |
testcase_04 | AC | 64 ms
71,232 KB |
testcase_05 | AC | 66 ms
71,056 KB |
testcase_06 | AC | 61 ms
71,292 KB |
testcase_07 | AC | 63 ms
71,336 KB |
testcase_08 | AC | 62 ms
71,288 KB |
testcase_09 | AC | 63 ms
71,396 KB |
testcase_10 | AC | 63 ms
71,276 KB |
testcase_11 | AC | 63 ms
71,296 KB |
testcase_12 | AC | 63 ms
70,924 KB |
testcase_13 | AC | 64 ms
71,084 KB |
testcase_14 | AC | 66 ms
71,268 KB |
testcase_15 | AC | 65 ms
71,440 KB |
testcase_16 | AC | 64 ms
71,256 KB |
testcase_17 | AC | 65 ms
71,432 KB |
testcase_18 | AC | 64 ms
71,204 KB |
testcase_19 | AC | 64 ms
71,336 KB |
testcase_20 | AC | 63 ms
71,056 KB |
testcase_21 | AC | 66 ms
71,248 KB |
testcase_22 | AC | 63 ms
71,248 KB |
testcase_23 | AC | 63 ms
71,248 KB |
testcase_24 | AC | 64 ms
71,224 KB |
testcase_25 | AC | 66 ms
71,376 KB |
testcase_26 | AC | 66 ms
71,216 KB |
testcase_27 | AC | 65 ms
71,344 KB |
testcase_28 | AC | 65 ms
71,060 KB |
testcase_29 | AC | 65 ms
71,336 KB |
testcase_30 | AC | 62 ms
71,080 KB |
testcase_31 | AC | 63 ms
71,440 KB |
testcase_32 | AC | 62 ms
71,068 KB |
ソースコード
import sys input=lambda:sys.stdin.readline().rstrip() class unionFind: def __init__(self,N): self.N=N self.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]=1 for 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)