結果

問題 No.2095 High Rise
ユーザー 👑 箱
提出日時 2022-02-17 07:08:26
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 778 ms / 2,000 ms
コード長 1,406 bytes
コンパイル時間 20,979 ms
コンパイル使用メモリ 420,616 KB
実行使用メモリ 104,884 KB
最終ジャッジ日時 2023-09-02 22:32:28
合計ジャッジ時間 37,791 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 303 ms
53,840 KB
testcase_01 AC 303 ms
53,916 KB
testcase_02 AC 272 ms
54,040 KB
testcase_03 AC 290 ms
53,688 KB
testcase_04 AC 294 ms
53,928 KB
testcase_05 AC 294 ms
54,436 KB
testcase_06 AC 291 ms
55,716 KB
testcase_07 AC 291 ms
55,740 KB
testcase_08 AC 275 ms
54,304 KB
testcase_09 AC 271 ms
52,040 KB
testcase_10 AC 292 ms
53,736 KB
testcase_11 AC 289 ms
53,712 KB
testcase_12 AC 306 ms
56,460 KB
testcase_13 AC 312 ms
56,148 KB
testcase_14 AC 377 ms
57,028 KB
testcase_15 AC 317 ms
57,940 KB
testcase_16 AC 347 ms
56,340 KB
testcase_17 AC 578 ms
60,208 KB
testcase_18 AC 532 ms
58,516 KB
testcase_19 AC 465 ms
61,964 KB
testcase_20 AC 574 ms
64,164 KB
testcase_21 AC 585 ms
66,572 KB
testcase_22 AC 773 ms
103,148 KB
testcase_23 AC 752 ms
102,796 KB
testcase_24 AC 778 ms
104,656 KB
testcase_25 AC 757 ms
102,924 KB
testcase_26 AC 759 ms
104,884 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) { 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 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