結果

問題 No.1231 Make a Multiple of Ten
ユーザー rutilicus
提出日時 2020-09-19 21:45:39
言語 Kotlin
(2.1.0)
結果
AC  
実行時間 709 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 14,728 ms
コンパイル使用メモリ 438,312 KB
実行使用メモリ 90,476 KB
最終ジャッジ日時 2024-06-23 19:23:38
合計ジャッジ時間 22,685 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
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