結果

問題 No.2095 High Rise
ユーザー 👑 箱
提出日時 2022-03-05 05:42:28
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 692 ms / 2,000 ms
コード長 1,265 bytes
コンパイル時間 17,500 ms
コンパイル使用メモリ 424,388 KB
実行使用メモリ 74,996 KB
最終ジャッジ日時 2023-09-02 22:34:09
合計ジャッジ時間 27,857 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 293 ms
55,800 KB
testcase_01 AC 294 ms
55,632 KB
testcase_02 AC 275 ms
52,456 KB
testcase_03 AC 296 ms
55,648 KB
testcase_04 AC 300 ms
56,020 KB
testcase_05 AC 296 ms
54,188 KB
testcase_06 AC 300 ms
53,728 KB
testcase_07 AC 297 ms
55,640 KB
testcase_08 AC 274 ms
52,232 KB
testcase_09 AC 274 ms
52,724 KB
testcase_10 AC 295 ms
53,896 KB
testcase_11 AC 294 ms
55,884 KB
testcase_12 AC 307 ms
58,144 KB
testcase_13 AC 311 ms
59,064 KB
testcase_14 AC 381 ms
59,328 KB
testcase_15 AC 319 ms
56,124 KB
testcase_16 AC 306 ms
56,004 KB
testcase_17 AC 528 ms
62,684 KB
testcase_18 AC 486 ms
60,236 KB
testcase_19 AC 428 ms
58,752 KB
testcase_20 AC 529 ms
58,720 KB
testcase_21 AC 572 ms
62,684 KB
testcase_22 AC 681 ms
72,992 KB
testcase_23 AC 688 ms
74,996 KB
testcase_24 AC 686 ms
74,848 KB
testcase_25 AC 692 ms
73,276 KB
testcase_26 AC 685 ms
74,988 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) { LongArray(m) { nextLong() } }
    if (n == 1) {
        println(0)
        return
    }
    val dp = Array(n + 1) { LongArray(m) { 0 } }
    for (i in 0 until n) {
        val min = dp[i].minOrNull()!!
        for (j in 0 until m) {
            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 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