結果
問題 | No.74 貯金箱の退屈 |
ユーザー |
![]() |
提出日時 | 2017-08-05 09:14:40 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,312 bytes |
コンパイル時間 | 3,377 ms |
コンパイル使用メモリ | 65,664 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-30 01:59:31 |
合計ジャッジ時間 | 4,198 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
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] mod 2 == 1 and flag[n] == false: echo "No" break answer echo "Yes"