結果

問題 No.74 貯金箱の退屈
ユーザー maspymaspy
提出日時 2020-03-07 07:31:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 1,060 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-22 12:11:45
合計ジャッジ時間 2,340 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,752 KB
testcase_01 AC 32 ms
11,008 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 31 ms
11,008 KB
testcase_04 AC 32 ms
10,880 KB
testcase_05 AC 32 ms
10,752 KB
testcase_06 AC 31 ms
10,880 KB
testcase_07 AC 31 ms
11,008 KB
testcase_08 AC 32 ms
11,008 KB
testcase_09 AC 32 ms
10,752 KB
testcase_10 AC 31 ms
11,008 KB
testcase_11 AC 32 ms
10,880 KB
testcase_12 AC 33 ms
10,752 KB
testcase_13 AC 32 ms
11,008 KB
testcase_14 AC 31 ms
11,008 KB
testcase_15 AC 32 ms
11,008 KB
testcase_16 AC 31 ms
10,752 KB
testcase_17 AC 32 ms
10,880 KB
testcase_18 AC 32 ms
10,752 KB
testcase_19 AC 32 ms
10,880 KB
testcase_20 AC 32 ms
10,752 KB
testcase_21 AC 32 ms
10,880 KB
testcase_22 AC 31 ms
10,752 KB
testcase_23 AC 32 ms
11,008 KB
testcase_24 AC 33 ms
11,008 KB
testcase_25 AC 31 ms
11,008 KB
testcase_26 AC 32 ms
11,008 KB
testcase_27 AC 32 ms
11,008 KB
testcase_28 AC 32 ms
11,008 KB
testcase_29 AC 32 ms
10,880 KB
testcase_30 AC 31 ms
11,008 KB
testcase_31 AC 32 ms
10,880 KB
testcase_32 AC 32 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
N = int(readline())
D = list(map(int, readline().split()))
W = list(map(int, readline().split()))

# %%
graph = [[] for _ in range(N)]
free = set()
for i, x in enumerate(D):
    j = (i + x) % N
    k = (i - x) % N
    if j == k:
        free.add(j)
    graph[j].append(k)
    graph[k].append(j)


# %%
comp = [0] * N
n = 0
for v in range(N):
    if comp[v]:
        continue
    n += 1
    comp[v] = n
    stack = [v]
    while stack:
        v = stack.pop()
        for w in graph[v]:
            if comp[w]:
                continue
            comp[w] = n
            stack.append(w)

# %%
comp_ind = [[] for _ in range(max(comp) + 1)]
for i, x in enumerate(comp):
    comp_ind[x].append(i)


# %%
answer = 'Yes'
for ind in comp_ind:
    is_free = bool(set(ind) & free)
    if is_free:
        continue
    ura = sum(1 - W[i] for i in ind)
    if ura & 1:
        answer = 'No'
        break
print(answer)
0