結果

問題 No.74 貯金箱の退屈
ユーザー 6soukiti296soukiti29
提出日時 2017-08-05 09:09:16
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 1,300 bytes
コンパイル時間 3,057 ms
コンパイル使用メモリ 69,132 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-12 13:53:51
合計ジャッジ時間 4,463 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 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,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 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] = true
    else:
        B.union(p,q)

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] mod 2 == 1 and flag[n] == false:
            echo "No"
            break answer
    echo "Yes"
0