結果

問題 No.5 数字のブロック
ユーザー Keita Yamada
提出日時 2021-04-12 22:22:51
言語 Kotlin
(2.1.0)
結果
WA  
実行時間 -
コード長 484 bytes
コンパイル時間 12,573 ms
コンパイル使用メモリ 442,996 KB
実行使用メモリ 299,320 KB
最終ジャッジ日時 2024-06-28 17:55:36
合計ジャッジ時間 76,021 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12 WA * 10 RE * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
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