結果
問題 | No.94 圏外です。(EASY) |
ユーザー |
![]() |
提出日時 | 2016-12-18 17:40:25 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 443 ms / 5,000 ms |
コード長 | 1,623 bytes |
コンパイル時間 | 14,547 ms |
コンパイル使用メモリ | 440,500 KB |
実行使用メモリ | 53,700 KB |
最終ジャッジ日時 | 2024-11-20 07:21:29 |
合計ジャッジ時間 | 23,713 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used fun main(args: Array<String>) { ^
ソースコード
fun main(args: Array<String>) { val N = readLine()!!.toInt() if (N == 0) { println(1) return } val X = Array(N, {0}) val Y = Array(N, {0}) (0 until N).forEach { val xy = readLine()!!.split(" ").map { it.toInt() } X[it] = xy.first() Y[it] = xy.last() } val union = UnionFind(N) (0 until N).forEach { i -> (i+1 until N).forEach { j -> if (distNotSqrt(X[i] - X[j], Y[i] - Y[j]) <= 100) { union.union(i, j) } } } var mx = 0 (0 until N).forEach { i -> (i+1 until N).forEach { j -> if (union.isSame(i, j)) { val len = distNotSqrt(X[i] - X[j], Y[i] - Y[j]) if (mx < len) mx = len } } } println(Math.sqrt(mx.toDouble()) + 2) } fun distNotSqrt(a: Int, b: Int) = a * a + b * b class UnionFind(N : Int) { val parent = Array(N, { i -> i }) val rank = Array(N, { 0 }) fun union(a : Int, b : Int) : Boolean { val Aroot = find(a) val Broot = find(b) if (Aroot == Broot) return false if (rank[Aroot] > rank[Broot]) { parent[Broot] = Aroot } else if (rank[Aroot] < rank[Broot]) { parent[Aroot] = Broot } else { parent[Aroot] = Broot rank[Broot]++ } return true } fun find(a : Int) : Int { if (parent[a] == a) { return a } else { return find(parent[a]) } } fun isSame(a : Int, b : Int) : Boolean = find(a) == find(b) }