結果

問題 No.74 貯金箱の退屈
ユーザー roarisroaris
提出日時 2019-08-29 22:46:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 1,439 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 52,992 KB
最終ジャッジ日時 2024-04-28 21:19:45
合計ジャッジ時間 2,417 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,968 KB
testcase_01 AC 38 ms
52,480 KB
testcase_02 AC 38 ms
52,480 KB
testcase_03 AC 39 ms
52,096 KB
testcase_04 AC 38 ms
52,608 KB
testcase_05 AC 38 ms
52,608 KB
testcase_06 AC 38 ms
52,608 KB
testcase_07 AC 38 ms
52,096 KB
testcase_08 AC 39 ms
52,608 KB
testcase_09 AC 39 ms
52,480 KB
testcase_10 AC 38 ms
52,480 KB
testcase_11 AC 39 ms
52,480 KB
testcase_12 AC 38 ms
52,480 KB
testcase_13 AC 38 ms
52,352 KB
testcase_14 AC 38 ms
52,608 KB
testcase_15 AC 39 ms
52,992 KB
testcase_16 AC 37 ms
52,224 KB
testcase_17 AC 38 ms
52,096 KB
testcase_18 AC 38 ms
51,968 KB
testcase_19 AC 37 ms
52,480 KB
testcase_20 AC 39 ms
52,224 KB
testcase_21 AC 37 ms
52,736 KB
testcase_22 AC 38 ms
52,352 KB
testcase_23 AC 36 ms
52,224 KB
testcase_24 AC 38 ms
52,224 KB
testcase_25 AC 37 ms
52,352 KB
testcase_26 AC 38 ms
52,736 KB
testcase_27 AC 38 ms
52,608 KB
testcase_28 AC 38 ms
52,608 KB
testcase_29 AC 38 ms
52,480 KB
testcase_30 AC 37 ms
52,480 KB
testcase_31 AC 39 ms
52,864 KB
testcase_32 AC 38 ms
52,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class Unionfind:
    def __init__(self, n):
        self.par = [-1] * n
        self.rank = [1] * n
    
    def root(self, x):
        if self.par[x] < 0:
            return x
            
        self.par[x] = self.root(self.par[x])
        
        return self.par[x]
    
    def unite(self, x, y):
        rx, ry = self.root(x), self.root(y)
        
        if rx != ry:
            if self.rank[rx] >= self.rank[ry]:
                self.par[rx] += self.par[ry]
                self.par[ry] = rx
                
                if self.rank[rx] == self.rank[ry]:
                    self.rank[rx] += 1
            else:
                self.par[ry] += self.par[rx]
                self.par[rx] = ry
    
    def is_same(self, x, y):
        return self.root(x) == self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

N = int(input())
D = list(map(int, input().split()))
W = list(map(int, input().split()))
uf = Unionfind(N)
s = []

for i in range(N):
    if (i+D[i])%N == (i-D[i])%N:
        s.append((i+D[i])%N)
        
    uf.unite((i+D[i])%N, (i-D[i])%N)

d = {i: [0, 0, 0] for i in range(N)}

for i in range(N):
    d[uf.root(i)][W[i]] += 1
    
    if i in s:
        d[uf.root(i)][2] += 1

for i in range(N):
    if d[i] == [0, 0, 0]:
        continue
    
    if d[i][2] == 0 and d[i][0] % 2 == 1:
        print('No')
        break
else:
    print('Yes')
0