結果
問題 | No.860 買い物 |
ユーザー | 6soukiti29 |
提出日時 | 2019-08-16 23:47:32 |
言語 | Nim (2.0.2) |
結果 |
AC
|
実行時間 | 165 ms / 1,000 ms |
コード長 | 1,457 bytes |
コンパイル時間 | 3,236 ms |
コンパイル使用メモリ | 71,784 KB |
実行使用メモリ | 23,632 KB |
最終ジャッジ日時 | 2023-09-15 12:35:23 |
合計ジャッジ時間 | 5,886 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
4,608 KB |
testcase_01 | AC | 3 ms
4,544 KB |
testcase_02 | AC | 3 ms
4,684 KB |
testcase_03 | AC | 3 ms
4,552 KB |
testcase_04 | AC | 3 ms
4,556 KB |
testcase_05 | AC | 3 ms
4,580 KB |
testcase_06 | AC | 8 ms
5,336 KB |
testcase_07 | AC | 164 ms
23,444 KB |
testcase_08 | AC | 164 ms
23,632 KB |
testcase_09 | AC | 165 ms
23,624 KB |
testcase_10 | AC | 164 ms
23,508 KB |
testcase_11 | AC | 122 ms
23,476 KB |
testcase_12 | AC | 117 ms
23,448 KB |
testcase_13 | AC | 157 ms
23,476 KB |
testcase_14 | AC | 156 ms
23,620 KB |
testcase_15 | AC | 111 ms
23,456 KB |
testcase_16 | AC | 157 ms
23,488 KB |
testcase_17 | AC | 93 ms
23,612 KB |
ソースコード
import sequtils,strutils,algorithm type unionfindtree[I : static[int]] = array[I,int] proc initUT(I : static[int]):unionfindtree[I] = var res : unionfindtree[I] for i in 0..<I: res[i] = i return res proc find(U : var 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] var s2 = a t2 = b p : int while s2 != s: p = U[s2] U[s2] = s s2 = p while t2 != t: p = U[t2] U[t2] = t t2 = p 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 BIT = initUT(100010) c,d,ans : int64 type edge = tuple[a : int ,b : int,c : int64] var edges = newSeq[edge](0) for i in 1..N: (c, d) =stdin.readline.split.map(parseBiggestInt) if i != 1: edges.add((i, i - 1, d)) edges.add((i, 0, c)) ans += c edges = edges.sortedByIt(it.c) for e in edges: if BIT.find(e.a,e.b) == false: ans += e.c BIT.union(e.a,e.b) echo ans