結果

問題 No.2095 High Rise
ユーザー 👑 箱
提出日時 2021-10-21 22:27:47
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 1,443 bytes
コンパイル時間 17,782 ms
コンパイル使用メモリ 431,872 KB
実行使用メモリ 70,404 KB
最終ジャッジ日時 2023-09-02 22:35:24
合計ジャッジ時間 33,757 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 318 ms
53,748 KB
testcase_01 AC 323 ms
53,904 KB
testcase_02 AC 289 ms
52,620 KB
testcase_03 AC 315 ms
55,736 KB
testcase_04 AC 317 ms
55,800 KB
testcase_05 AC 323 ms
55,632 KB
testcase_06 AC 321 ms
55,508 KB
testcase_07 AC 315 ms
56,008 KB
testcase_08 AC 299 ms
54,456 KB
testcase_09 AC 298 ms
52,016 KB
testcase_10 AC 321 ms
55,676 KB
testcase_11 AC 317 ms
54,428 KB
testcase_12 AC 376 ms
58,900 KB
testcase_13 AC 349 ms
58,740 KB
testcase_14 AC 445 ms
59,760 KB
testcase_15 AC 384 ms
58,516 KB
testcase_16 AC 363 ms
57,040 KB
testcase_17 AC 1,367 ms
67,168 KB
testcase_18 AC 869 ms
66,376 KB
testcase_19 AC 526 ms
62,244 KB
testcase_20 AC 1,980 ms
70,404 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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) {
        for (j in 0 until m) {
            for (k in 0 until m) {
                if (j != k) {
                    dp[i + 1][j] = minOf(dp[i + 1][j], dp[i][k] + a[i][j] + if (i >= 1) a[i - 1][j] else 0)
                } else {
                    dp[i + 1][j] = minOf(dp[i + 1][j], 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", 1.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