結果

問題 No.74 貯金箱の退屈
ユーザー 6soukiti296soukiti29
提出日時 2017-08-05 09:17:22
言語 Nim
(2.0.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,314 bytes
コンパイル時間 3,018 ms
コンパイル使用メモリ 68,932 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 13:53:46
合計ジャッジ時間 4,900 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import sequtils,strutils

type
    unionfindtree[I : static[int]] = array[I,int]

proc find(U : unionfindtree; a : int, b :int): bool=
    var
        s = a
        t = b
    while s != U[s]:
        s = U[s]
    while t != U[t]:
        t = U[t]
    return s == t
    
proc union(U : var  unionfindtree; a : int ; b : int)=
    if U.find(a,b):
        return
    var
        s = a
        t = b
        t2 : int
    while s != U[s]:
        s = U[s]
    while t != U[t]:
        t2 = U[t]
        U[t] = s
        t = t2
    U[t] = s

proc root(U : unionfindtree, a :int):int=
    var
        s = a
    while s != U[s]:
        s = U[s]
    return s

var
    N = stdin.readline.parseInt
    D = stdin.readline.split.map(parseInt)
    W = stdin.readline.split.map(parseInt)
    flag : array[101,bool]
    B : unionfindtree[101]
    cnt : array[101,int]
    
for i in 1..N:
    B[i] = i

for i,d in D:
    var
        p = (i + d) mod N
        q = (i - d + 1000 * N) mod N
    if p == q:
        flag[p + 1] = true
    else:
        B.union(p + 1,q + 1)

for n in 1..N:
    if W[n - 1] == 0:
        cnt[B.root(n)] += 1
    if flag[n]:
        flag[B.root(n)] = true

block answer:
    for n in 1..N:
        if (cnt[n] and 1) == 1 and flag[n] == false:
            echo "No"
            break answer
    echo "Yes"
0