結果

問題 No.74 貯金箱の退屈
ユーザー H3PO4H3PO4
提出日時 2020-04-24 13:58:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,047 ms / 5,000 ms
コード長 724 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 57,036 KB
最終ジャッジ日時 2024-04-23 02:29:16
合計ジャッジ時間 38,513 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 980 ms
56,652 KB
testcase_01 AC 1,035 ms
56,652 KB
testcase_02 AC 1,047 ms
56,784 KB
testcase_03 AC 978 ms
56,912 KB
testcase_04 AC 979 ms
56,908 KB
testcase_05 AC 984 ms
56,908 KB
testcase_06 AC 998 ms
56,528 KB
testcase_07 AC 983 ms
56,784 KB
testcase_08 AC 985 ms
57,032 KB
testcase_09 AC 976 ms
56,776 KB
testcase_10 AC 984 ms
56,788 KB
testcase_11 AC 975 ms
56,788 KB
testcase_12 AC 970 ms
56,912 KB
testcase_13 AC 975 ms
56,780 KB
testcase_14 AC 984 ms
56,780 KB
testcase_15 AC 987 ms
56,660 KB
testcase_16 AC 1,019 ms
57,036 KB
testcase_17 AC 975 ms
56,648 KB
testcase_18 AC 984 ms
56,524 KB
testcase_19 AC 1,000 ms
56,784 KB
testcase_20 AC 989 ms
56,792 KB
testcase_21 AC 996 ms
56,912 KB
testcase_22 AC 982 ms
56,876 KB
testcase_23 AC 993 ms
56,908 KB
testcase_24 AC 1,022 ms
56,660 KB
testcase_25 AC 996 ms
56,788 KB
testcase_26 AC 983 ms
57,032 KB
testcase_27 AC 1,001 ms
56,780 KB
testcase_28 AC 989 ms
56,784 KB
testcase_29 AC 979 ms
56,788 KB
testcase_30 AC 982 ms
56,788 KB
testcase_31 AC 982 ms
56,656 KB
testcase_32 AC 989 ms
56,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix

N = int(input())
D = tuple(map(int, input().split()))
W = tuple(map(int, input().split()))

same_set = set()
edge = []
for i, d in enumerate(D):
    if (p := (i - d) % N) == (q := (i + d) % N):
        same_set.add(p)
    else:
        edge.append((p, q))
edge = np.array(edge).T

matr = csr_matrix((np.ones(len(edge[0]), dtype="int64"), edge), (N, N))
p, labels = connected_components(matr)

lst = [set() for _ in range(p)]
for i, x in enumerate(labels):
    lst[x].add(i)
for st in lst:
    if st.isdisjoint(same_set) and sum((1 - W[i]) for i in st) % 2:
        print('No')
        break
else:
    print('Yes')
0