結果
問題 | No.168 ものさし |
ユーザー |
|
提出日時 | 2019-01-30 22:51:52 |
言語 | Nim (2.2.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,849 bytes |
コンパイル時間 | 2,947 ms |
コンパイル使用メモリ | 62,816 KB |
実行使用メモリ | 43,976 KB |
最終ジャッジ日時 | 2024-07-01 11:13:50 |
合計ジャッジ時間 | 5,387 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 4 |
other | WA * 19 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]
ソースコード
import sequtils,algorithm,mathtemplate `max=`*(x,y) = x = max(x,y)template useUnionFind() =type UnionFind[T] = objectparent : seq[T]proc initUnionFind[T](size:int) : UnionFind[T] =result.parent = newSeqUninitialized[T](size)for i in 0.int32..<size.int32: result.parent[i] = iproc root[T](self:var UnionFind[T],x:T): T =if self.parent[x] == x: return xself.parent[x] = self.root(self.parent[x])return self.parent[x]proc same[T](self:var UnionFind[T],x,y:T) : bool = self.root(x) == self.root(y)proc merge[T](self:var UnionFind[T],sx,sy:T) : bool {.discardable.} =var rx = self.root(sx)var ry = self.root(sy)if rx == ry : return falseif self.parent[ry] < self.parent[rx] : swap(rx,ry)if self.parent[rx] == self.parent[ry] : self.parent[rx] -= 1self.parent[ry] = rxreturn trueuseUnionFind()proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}proc scan(): int =while true:let k = getchar_unlocked()if k < '0': returnresult = 10 * result + k.ord - '0'.ordtype Edge = tuple[cost,src,dst:int]proc kruskal(E:seq[Edge],maxN:int) : int = # 0..<maxN, unionfind# 最小全域木 とそのコストを返却var uf = initUnionFind[int](maxN)for e in E.sortedByIt(it.cost):if uf.same(e.src,e.dst) : continueuf.merge(e.src,e.dst)result .max= e.costif uf.same(0,maxN-1): break # 繋げたい点があればlet n = scan()var X = newSeq[int](n)var Y = newSeq[int](n)for i in 0..<n:X[i] = scan()Y[i] = scan()var E = newSeq[Edge]()for a in 0..<n:for b in (a+1)..<n:var d = (X[a] - X[b])*(X[a] - X[b])d += (Y[a] - Y[b])*(Y[a] - Y[b])E &= (d,a,b)let ans = E.kruskal(n)for i in ans.float.sqrt.int..int.high:var i = i div 10 * 10if i * i < ans : continuequit $i,0