結果

問題 No.5 数字のブロック
ユーザー Keita YamadaKeita Yamada
提出日時 2021-04-12 22:22:51
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 484 bytes
コンパイル時間 14,523 ms
コンパイル使用メモリ 420,316 KB
実行使用メモリ 298,964 KB
最終ジャッジ日時 2023-09-11 03:24:05
合計ジャッジ時間 70,241 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 322 ms
57,424 KB
testcase_01 WA -
testcase_02 AC 318 ms
57,008 KB
testcase_03 RE -
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 324 ms
57,108 KB
testcase_21 AC 316 ms
57,096 KB
testcase_22 AC 315 ms
57,148 KB
testcase_23 AC 322 ms
57,048 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 323 ms
57,156 KB
testcase_27 AC 323 ms
57,444 KB
testcase_28 AC 330 ms
57,156 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 333 ms
57,108 KB
testcase_32 AC 332 ms
57,256 KB
testcase_33 AC 319 ms
57,268 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:9: warning: variable 'N' is never used
    val N = readLine()!!.toInt() 
        ^
Main.kt:16:42: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Pair<Int, Int>
    println(dp.map{ it.maxBy{ it.second }!!.second }.max())
                                         ^

ソースコード

diff #

fun main() {
    val L = readLine()!!.toInt() 
    val N = readLine()!!.toInt() 
    val W = readLine()!!.split(" ").map(String::toInt)

    var dp = Array(W.size + 1) { Array(L + 1){ 0 to 0 } }

    for(i in 1..W.size) for(k in 0..L) {
        if(W[i-1] + dp[i-1][k].first <= k){
            dp[i][k] = (dp[i-1][k].first + W[i-1] to dp[i-1][k].second + 1)
        }else{
            dp[i][k] = dp[i-1][k]
        }
    }

    println(dp.map{ it.maxBy{ it.second }!!.second }.max())
}
0