結果

問題 No.1231 Make a Multiple of Ten
ユーザー 👑 箱星箱星
提出日時 2020-09-19 04:26:24
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 487 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 14,378 ms
コンパイル使用メモリ 425,740 KB
実行使用メモリ 62,616 KB
最終ジャッジ日時 2023-09-05 18:27:13
合計ジャッジ時間 20,827 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 272 ms
50,344 KB
testcase_01 AC 267 ms
50,868 KB
testcase_02 AC 267 ms
50,432 KB
testcase_03 AC 265 ms
50,408 KB
testcase_04 AC 455 ms
55,968 KB
testcase_05 AC 458 ms
56,008 KB
testcase_06 AC 409 ms
55,936 KB
testcase_07 AC 430 ms
56,020 KB
testcase_08 AC 417 ms
55,952 KB
testcase_09 AC 402 ms
55,740 KB
testcase_10 AC 433 ms
55,916 KB
testcase_11 AC 435 ms
58,020 KB
testcase_12 AC 478 ms
62,308 KB
testcase_13 AC 487 ms
62,280 KB
testcase_14 AC 267 ms
50,392 KB
testcase_15 AC 484 ms
62,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    var dp = IntArray(10) { -1 }
    dp[0] = 0
    for (i in 0 until n) {
        val newdp = dp.copyOf()
        for (j in 0 until 10) {
            val k = (a[i] + j) % 10
            if (dp[j] != -1) {
                newdp[k] = maxOf(newdp[k], dp[j] + 1)
            }
        }
        dp = newdp
    }
    println(dp[0])
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}
0