結果

問題 No.2095 High Rise
ユーザー 👑 箱
提出日時 2022-09-19 18:12:01
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,341 ms / 2,000 ms
コード長 735 bytes
コンパイル時間 17,505 ms
コンパイル使用メモリ 418,068 KB
実行使用メモリ 101,780 KB
最終ジャッジ日時 2023-09-02 22:38:39
合計ジャッジ時間 31,875 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 315 ms
56,856 KB
testcase_01 AC 324 ms
56,740 KB
testcase_02 AC 295 ms
52,608 KB
testcase_03 AC 324 ms
56,656 KB
testcase_04 AC 331 ms
56,664 KB
testcase_05 AC 322 ms
56,604 KB
testcase_06 AC 326 ms
56,764 KB
testcase_07 AC 322 ms
56,604 KB
testcase_08 AC 303 ms
52,796 KB
testcase_09 AC 301 ms
52,724 KB
testcase_10 AC 338 ms
56,612 KB
testcase_11 AC 333 ms
56,964 KB
testcase_12 AC 380 ms
57,044 KB
testcase_13 AC 371 ms
56,972 KB
testcase_14 AC 422 ms
57,224 KB
testcase_15 AC 396 ms
57,168 KB
testcase_16 AC 372 ms
56,888 KB
testcase_17 AC 683 ms
63,200 KB
testcase_18 AC 652 ms
63,268 KB
testcase_19 AC 532 ms
60,624 KB
testcase_20 AC 714 ms
65,296 KB
testcase_21 AC 888 ms
69,988 KB
testcase_22 AC 1,310 ms
101,616 KB
testcase_23 AC 1,341 ms
101,780 KB
testcase_24 AC 1,339 ms
101,656 KB
testcase_25 AC 1,328 ms
101,520 KB
testcase_26 AC 1,339 ms
101,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fun main() {
    val (n, m) = nextInts()
    val a = Array(n) { nextLongs() }
    if (n == 1) {
        println(0)
        return
    }
    val dp = Array(n + 1) { LongArray(m) { Long.MAX_VALUE / 2 } }
    for (i in 0 until m) {
        dp[0][i] = 0
    }
    for (i in 0 until n) {
        val min = dp[i].minOrNull()!!
        for (j in 0 until m) {
            if (dp[i][j] == min) {
                dp[i + 1][j] = min + a[i][j]
            } else {
                dp[i + 1][j] = minOf(min + a[i][j] + if (i >= 1) a[i - 1][j] else 0, dp[i][j] + a[i][j])
            }
        }
    }
    println(dp[n].minOrNull())
}

fun nextInts() = readln().split(" ").map { it.toInt() }
fun nextLongs() = readln().split(" ").map { it.toLong() }
0