提出 #58678343


ソースコード 拡げる

import kotlin.math.sqrt

fun main() {
    val n = readln().toInt()
    val xy = List(n) {
        val (x, y) = readln().split(" ").map { it.toLong() }
        x to y
    }

    var ans = 0.0

    var current = 0L to 0L

    for((x, y) in xy) {
        val (a, b) = current
        val d = calc(a, b, x, y)
        ans += d

        current = x to y
    }

    val (a, b) = current
    ans += calc(a, b, 0, 0)

    println(ans)
}

fun calc(a: Long, b: Long, c: Long, d: Long): Double {
    val diff1 = a - c
    val diff2 = b - d

    return sqrt((diff1 * diff1 + diff2 * diff2).toDouble())
}

提出情報

提出日時
問題 B - Traveling Takahashi Problem
ユーザ dhirabayashi
言語 Kotlin (Kotlin/JVM 1.8.20)
得点 150
コード長 625 Byte
結果 AC
実行時間 417 ms
メモリ 76476 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 150 / 150
結果
AC × 3
AC × 14
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 320 ms 66240 KiB
random_02.txt AC 257 ms 63860 KiB
random_03.txt AC 318 ms 65980 KiB
random_04.txt AC 205 ms 60284 KiB
random_05.txt AC 417 ms 76396 KiB
random_06.txt AC 213 ms 59920 KiB
random_07.txt AC 387 ms 76020 KiB
random_08.txt AC 123 ms 45820 KiB
random_09.txt AC 60 ms 39856 KiB
random_10.txt AC 60 ms 39736 KiB
random_11.txt AC 403 ms 76476 KiB
sample_01.txt AC 57 ms 39908 KiB
sample_02.txt AC 56 ms 39988 KiB
sample_03.txt AC 58 ms 39928 KiB