結果
問題 |
No.2095 High Rise
|
ユーザー |
|
提出日時 | 2022-09-19 18:12:01 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 1,191 ms / 2,000 ms |
コード長 | 735 bytes |
コンパイル時間 | 14,387 ms |
コンパイル使用メモリ | 444,780 KB |
実行使用メモリ | 117,460 KB |
最終ジャッジ日時 | 2024-06-12 04:50:17 |
合計ジャッジ時間 | 31,416 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
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() }