結果

問題 No.2095 High Rise
ユーザー 👑 箱
提出日時 2022-02-17 06:53:14
言語 Kotlin
(1.9.10)
結果
AC  
実行時間 935 ms / 2,000 ms
コード長 1,489 bytes
コンパイル時間 16,148 ms
コンパイル使用メモリ 428,800 KB
実行使用メモリ 132,944 KB
最終ジャッジ日時 2023-09-02 22:36:28
合計ジャッジ時間 33,611 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 307 ms
54,052 KB
testcase_01 AC 304 ms
55,964 KB
testcase_02 AC 284 ms
54,392 KB
testcase_03 AC 302 ms
56,232 KB
testcase_04 AC 294 ms
54,504 KB
testcase_05 AC 300 ms
54,196 KB
testcase_06 AC 300 ms
56,004 KB
testcase_07 AC 297 ms
56,088 KB
testcase_08 AC 270 ms
52,564 KB
testcase_09 AC 277 ms
52,884 KB
testcase_10 AC 293 ms
54,068 KB
testcase_11 AC 303 ms
55,876 KB
testcase_12 AC 316 ms
58,120 KB
testcase_13 AC 313 ms
58,256 KB
testcase_14 AC 385 ms
58,540 KB
testcase_15 AC 325 ms
58,536 KB
testcase_16 AC 326 ms
58,332 KB
testcase_17 AC 547 ms
60,992 KB
testcase_18 AC 510 ms
64,548 KB
testcase_19 AC 447 ms
58,436 KB
testcase_20 AC 565 ms
66,776 KB
testcase_21 AC 632 ms
75,052 KB
testcase_22 AC 908 ms
130,924 KB
testcase_23 AC 917 ms
132,944 KB
testcase_24 AC 935 ms
132,916 KB
testcase_25 AC 909 ms
130,904 KB
testcase_26 AC 904 ms
130,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextInt()
    val m = nextInt()
    val a = Array(n) { Array(m) { nextLong() } }
    if (n == 1) {
        println(0)
        return
    }
    val dp = Array(n + 1) { Array(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] = minOf(dp[i + 1][j], min + a[i][j])
            } else {
                dp[i + 1][j] = minOf(dp[i + 1][j], min + a[i][j] + if (i >= 1) a[i - 1][j] else 0, dp[i][j] + a[i][j])
            }
        }
    }
    println(dp[n].minOrNull()!!)
}

fun main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", abs(1L.shl(26)))
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

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()
// endregion
0