結果

問題 No.1160 Strange Bowling
ユーザー rutilicusrutilicus
提出日時 2020-10-19 21:23:57
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 583 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 17,431 ms
コンパイル使用メモリ 420,624 KB
実行使用メモリ 63,728 KB
最終ジャッジ日時 2023-09-28 13:28:29
合計ジャッジ時間 37,445 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 301 ms
52,728 KB
testcase_01 AC 302 ms
52,816 KB
testcase_02 AC 299 ms
52,848 KB
testcase_03 AC 297 ms
52,648 KB
testcase_04 AC 318 ms
52,736 KB
testcase_05 AC 300 ms
52,744 KB
testcase_06 AC 301 ms
52,968 KB
testcase_07 AC 300 ms
52,628 KB
testcase_08 AC 296 ms
52,568 KB
testcase_09 AC 296 ms
52,640 KB
testcase_10 AC 583 ms
61,504 KB
testcase_11 AC 545 ms
59,408 KB
testcase_12 AC 510 ms
57,728 KB
testcase_13 AC 476 ms
57,836 KB
testcase_14 AC 567 ms
61,468 KB
testcase_15 AC 494 ms
57,812 KB
testcase_16 AC 511 ms
57,564 KB
testcase_17 AC 563 ms
61,408 KB
testcase_18 AC 532 ms
59,620 KB
testcase_19 AC 512 ms
60,324 KB
testcase_20 AC 539 ms
59,784 KB
testcase_21 AC 532 ms
59,452 KB
testcase_22 AC 501 ms
57,676 KB
testcase_23 AC 494 ms
57,784 KB
testcase_24 AC 491 ms
57,716 KB
testcase_25 AC 511 ms
59,356 KB
testcase_26 AC 507 ms
57,708 KB
testcase_27 AC 541 ms
59,348 KB
testcase_28 AC 503 ms
57,680 KB
testcase_29 AC 572 ms
61,616 KB
testcase_30 AC 583 ms
63,728 KB
testcase_31 AC 555 ms
61,536 KB
testcase_32 AC 509 ms
57,556 KB
testcase_33 AC 534 ms
59,328 KB
testcase_34 AC 532 ms
59,380 KB
testcase_35 AC 580 ms
63,616 KB
testcase_36 AC 306 ms
52,648 KB
testcase_37 AC 310 ms
52,872 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:26:13: warning: 'appendln(Long): kotlin.text.StringBuilder /* = java.lang.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(max(dp[0][0], dp[0][1]))
            ^

ソースコード

diff #

import kotlin.math.max

data class Pin(val p: Long, val a: Long)

fun main() {
    val builder = StringBuilder()

    val n = readInputLine().toInt()

    // そのラウンドで[0]: 全部倒す、[1]: aだけ倒す 場合の最大スコア
    val dp = Array(n) { LongArray(2) }

    val pin = Array(n) {
        val (p, a) = readInputLine().split(" ").map { it.toLong() }
        Pin(p, a)
    }

    dp[n - 1][0] = pin[n - 1].p
    dp[n - 1][1] = pin[n - 1].a

    for (i in n - 2 downTo 0) {
        dp[i][0] = max(dp[i + 1][0], dp[i + 1][1]) + pin[i].p
        dp[i][1] = max(dp[i + 1][0] + pin[i + 1].p, dp[i + 1][1] + pin[i + 1].a) + pin[i].a
    }

    builder.appendln(max(dp[0][0], dp[0][1]))

    print(builder.toString())
}

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