結果

問題 No.94 圏外です。(EASY)
ユーザー mura40424mura40424
提出日時 2016-12-18 17:32:04
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,558 bytes
コンパイル時間 13,682 ms
コンパイル使用メモリ 443,608 KB
実行使用メモリ 58,108 KB
最終ジャッジ日時 2024-04-30 12:23:01
合計ジャッジ時間 24,143 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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()
    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(mx)
}

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