結果

問題 No.94 圏外です。(EASY)
ユーザー mura40424mura40424
提出日時 2016-12-18 17:40:25
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 396 ms / 5,000 ms
コード長 1,623 bytes
コンパイル時間 11,197 ms
コンパイル使用メモリ 439,540 KB
実行使用メモリ 58,132 KB
最終ジャッジ日時 2024-04-30 12:23:40
合計ジャッジ時間 19,763 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 276 ms
57,136 KB
testcase_01 AC 277 ms
56,988 KB
testcase_02 AC 273 ms
56,992 KB
testcase_03 AC 256 ms
54,056 KB
testcase_04 AC 290 ms
57,064 KB
testcase_05 AC 300 ms
57,468 KB
testcase_06 AC 341 ms
57,616 KB
testcase_07 AC 371 ms
58,028 KB
testcase_08 AC 396 ms
57,988 KB
testcase_09 AC 379 ms
58,132 KB
testcase_10 AC 367 ms
57,992 KB
testcase_11 AC 379 ms
58,032 KB
testcase_12 AC 394 ms
58,016 KB
testcase_13 AC 380 ms
57,992 KB
testcase_14 AC 370 ms
57,948 KB
testcase_15 AC 377 ms
58,012 KB
testcase_16 AC 380 ms
58,036 KB
testcase_17 AC 366 ms
57,964 KB
testcase_18 AC 385 ms
58,012 KB
testcase_19 AC 382 ms
58,064 KB
testcase_20 AC 277 ms
57,232 KB
testcase_21 AC 281 ms
57,140 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

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)
}
0