結果
| 問題 |
No.74 貯金箱の退屈
|
| コンテスト | |
| ユーザー |
6soukiti29
|
| 提出日時 | 2017-08-05 09:09:16 |
| 言語 | Nim (2.2.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,300 bytes |
| コンパイル時間 | 3,336 ms |
| コンパイル使用メモリ | 65,536 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-30 01:59:22 |
| 合計ジャッジ時間 | 4,228 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 WA * 12 |
ソースコード
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"
6soukiti29