結果

問題 No.1265 Balloon Survival
コンテスト
ユーザー rutilicus
提出日時 2020-10-24 08:57:39
言語 Kotlin
(2.3.20)
コンパイル:
kotlinc _filename_ -include-runtime -d main.jar
実行:
kotlin main.jar
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,038 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9,208 ms
コンパイル使用メモリ 453,668 KB
最終ジャッジ日時 2026-04-03 05:02:48
合計ジャッジ時間 14,124 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Main.kt:42:13: error: 'fun StringBuilder.appendln(value: Int): StringBuilder' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
    builder.appendln(ans)
            ^^^^^^^^

ソースコード

diff #
raw source code

import java.util.*

fun main() {
    val builder = StringBuilder()

    val n = readInputLine().toInt()

    val balloon = Array(n) {
        val (x, y) = readInputLine().split(" ").map { it.toLong() }
        Pair(x, y)
    }

    val queue = PriorityQueue<Triple<Int, Int, Long>> { x, y -> x.third.compareTo(y.third) }

    for (i in 0 until n) {
        for (j in i + 1 until n) {
            val x = balloon[i].first - balloon[j].first
            val y = balloon[i].second - balloon[j].second
            queue.add(Triple(i, j, x * x + y * y))
        }
    }

    var ans = 0
    val removed = BooleanArray(n)

    while (queue.isNotEmpty()) {
        val (x, y, _) = queue.poll()!!

        if (removed[x] || removed[y]) {
            continue
        }

        if (x == 0 && !removed[y]) {
            ans++
        }
        if (x != 0) {
            removed[x] = true
        }
        removed[y] = true
    }

    builder.appendln(ans)

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}
0