結果
| 問題 | No.971 いたずらっ子 |
| コンテスト | |
| ユーザー |
yakamoto
|
| 提出日時 | 2020-01-17 21:41:38 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 796 ms / 2,000 ms |
| コード長 | 1,438 bytes |
| コンパイル時間 | 15,702 ms |
| コンパイル使用メモリ | 457,264 KB |
| 実行使用メモリ | 103,628 KB |
| 最終ジャッジ日時 | 2024-11-07 11:26:46 |
| 合計ジャッジ時間 | 30,004 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
import java.lang.Exception
import kotlin.math.max
import kotlin.math.min
val MOD = 1_000_000_007
fun main() {
val (H, W) = readInts()
val g = Array(H){readLn()}
val C = Array(H){IntArray(W){1} }
for (h in 0 until H) {
for (w in 0 until W) {
if (g[h][w] == 'k') C[h][w] += h + w
}
}
val inf = 1e18.toLong()
val dp = Array(H){LongArray(W){inf} }
dp[0][0] = 0
for (h in 0 until H) {
for (w in 0 until W) {
if (h - 1 >= 0) dp[h][w] = min(dp[h][w], dp[h-1][w] + C[h][w])
if (w - 1 >= 0) dp[h][w] = min(dp[h][w], dp[h][w-1] + C[h][w])
}
}
println(dp[H-1][W-1])
}
private val isDebug = try {
// なんか本番でエラーでる
System.getenv("MY_DEBUG") != null
} catch (t: Throwable) {
false
}
private fun readLn() = readLine()!!
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }.toIntArray()
private fun readLongs() = readStrings().map { it.toLong() }.toLongArray()
private inline fun debug(msg: () -> String) {
if (isDebug) System.err.println(msg())
}
private fun debug(a: LongArray) {
debug{a.joinToString(" ")}
}
private fun debug(a: IntArray) {
debug{a.joinToString(" ")}
}
private fun debug(a: BooleanArray) {
debug{a.map{if(it) 1 else 0}.joinToString("")}
}
private fun debugDim(A: Array<IntArray>) {
if (isDebug) {
for (a in A) {
debug(a)
}
}
}
yakamoto