結果

問題 No.168 ものさし
ユーザー バカらっくバカらっく
提出日時 2019-11-29 09:53:14
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,600 bytes
コンパイル時間 15,265 ms
コンパイル使用メモリ 429,644 KB
実行使用メモリ 59,196 KB
最終ジャッジ日時 2023-08-13 04:40:38
合計ジャッジ時間 25,086 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 413 ms
57,576 KB
testcase_01 AC 321 ms
57,068 KB
testcase_02 AC 317 ms
57,128 KB
testcase_03 AC 313 ms
56,836 KB
testcase_04 AC 311 ms
56,872 KB
testcase_05 WA -
testcase_06 AC 314 ms
56,804 KB
testcase_07 AC 319 ms
57,272 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 318 ms
56,856 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 408 ms
58,472 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:4:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^

ソースコード

diff #

import java.math.BigDecimal
import java.util.*

fun main(arr:Array<String>) {
    val pointCount = readLine()!!.toInt()
    var list = (1..pointCount).map {id -> readLine()!!.split(" ").map { it.toLong() }.let { Point(id, it[0].toDouble(), it[1].toDouble()) } }.toMutableList()
    list.forEach {
        it.distanceStart =  dist(it, list.first())
        it.distanceGoal = dist(it, list.last())
    }
    val startPoint = list.first()
    val goalPoint = list.last()

    list = list.filter { it.distanceGoal <= startPoint.distanceGoal && it.distanceStart <= goalPoint.distanceStart }.sortedBy { it.distanceStart }.toMutableList()
    val map = PriorityQueue<Point>(kotlin.Comparator { t, t2 -> t.distanceStart.compareTo(t2.distanceStart) })
    map.add(list.first())
    list.removeAt(0)

    for(p in list) {
        for(p2 in map) {
            val d = dist(p2, p)
            if(d <= p2.distanceStart) {
                p.distanceStart = p2.distanceStart
                break
            } else if(d < p.distanceStart) {
                p.distanceStart = d
            }
        }
        map.add(p)
    }
    println(goalPoint.distanceStart)
}

fun dist(p1:Point, p2:Point):Long {
    var dist = Math.pow(Math.abs(p1.x - p2.x), 2.toDouble())
    dist += Math.pow(Math.abs(p1.y - p2.y), 2.toDouble())
    var ret = Math.ceil(Math.sqrt(dist))
    if(ret * ret < dist) {
        ret += 1
    }
    if(ret % 10 > 0) {
        ret += 10
    }
    return ret.toLong() / 10 * 10
}

class Point(val id:Int, val x:Double, val y:Double) {
    var distanceStart: Long = 0
    var distanceGoal:Long = 0
}
0