結果

問題 No.74 貯金箱の退屈
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-01-13 23:49:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 1,168 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 52,864 KB
最終ジャッジ日時 2024-04-28 22:12:56
合計ジャッジ時間 2,955 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

class Unionfind:
 
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]


n = int(input())
D = list(map(int,input().split()))
W = list(map(int,input().split()))

single = [0]*n
uf = Unionfind(n)
for i,d in enumerate(D):
    a = (i+d)%n
    b = (i-d)%n

    if a == b:
        single[a] = 1

    uf.union(a,b)


count = [0]*n
ok = [0]*n
for i,w in enumerate(W):
    if w == 0:
        count[uf.find(i)] += 1
    if single[i]:
        ok[uf.find(i)] = 1

for i in range(n):
    if uf.find(i) != i:
        continue
    if count[i] % 2 == 0 or ok[i]:
        continue
    print("No")
    exit()
print("Yes") 
0