結果

問題 No.1231 Make a Multiple of Ten
ユーザー rutilicusrutilicus
提出日時 2020-09-19 21:45:39
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 672 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 13,977 ms
コンパイル使用メモリ 425,104 KB
実行使用メモリ 81,460 KB
最終ジャッジ日時 2023-09-06 00:16:11
合計ジャッジ時間 22,940 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 293 ms
52,960 KB
testcase_01 AC 291 ms
54,760 KB
testcase_02 AC 295 ms
52,880 KB
testcase_03 AC 292 ms
52,848 KB
testcase_04 AC 513 ms
63,792 KB
testcase_05 AC 500 ms
63,568 KB
testcase_06 AC 459 ms
57,840 KB
testcase_07 AC 509 ms
63,580 KB
testcase_08 AC 472 ms
57,908 KB
testcase_09 AC 461 ms
57,976 KB
testcase_10 AC 513 ms
63,784 KB
testcase_11 AC 570 ms
68,260 KB
testcase_12 AC 636 ms
74,556 KB
testcase_13 AC 672 ms
81,460 KB
testcase_14 AC 291 ms
52,836 KB
testcase_15 AC 667 ms
81,416 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:24:13: warning: 'appendln(Int): 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(dp[n][0])
            ^

ソースコード

diff #

import kotlin.math.max

fun main() {
    val builder = StringBuilder()

    val n = readInputLine().toInt()
    val aArr = readInputLine().split(" ").map { it.toInt() }.toIntArray()

    // 10の剰余を取った時の最大枚数
    val dp = Array(n + 1) { IntArray(10) { -1 } }

    dp[0][0] = 0

    for ((i, a) in aArr.withIndex()) {
        for (j in 0..9) {
            if (dp[i][j] == -1) {
                continue
            }
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
            dp[i + 1][(j + a) % 10] = max(dp[i + 1][(j + a) % 10], dp[i][j] + 1)
        }
    }

    builder.appendln(dp[n][0])

    print(builder.toString())
}

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