結果

問題 No.971 いたずらっ子
ユーザー yakamotoyakamoto
提出日時 2020-01-17 21:41:38
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 774 ms / 2,000 ms
コード長 1,438 bytes
コンパイル時間 15,603 ms
コンパイル使用メモリ 448,440 KB
実行使用メモリ 103,468 KB
最終ジャッジ日時 2024-04-25 01:58:08
合計ジャッジ時間 29,319 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 774 ms
103,224 KB
testcase_01 AC 770 ms
103,188 KB
testcase_02 AC 722 ms
100,060 KB
testcase_03 AC 737 ms
103,136 KB
testcase_04 AC 728 ms
103,468 KB
testcase_05 AC 740 ms
103,036 KB
testcase_06 AC 702 ms
100,808 KB
testcase_07 AC 362 ms
52,540 KB
testcase_08 AC 629 ms
72,264 KB
testcase_09 AC 652 ms
71,712 KB
testcase_10 AC 372 ms
52,620 KB
testcase_11 AC 319 ms
51,840 KB
testcase_12 AC 309 ms
51,760 KB
testcase_13 AC 302 ms
51,724 KB
testcase_14 AC 334 ms
52,208 KB
testcase_15 AC 313 ms
51,764 KB
testcase_16 AC 314 ms
51,944 KB
testcase_17 AC 300 ms
51,796 KB
testcase_18 AC 305 ms
51,752 KB
testcase_19 AC 303 ms
51,764 KB
testcase_20 AC 306 ms
51,680 KB
testcase_21 AC 302 ms
51,700 KB
testcase_22 AC 299 ms
51,892 KB
testcase_23 AC 305 ms
51,628 KB
testcase_24 AC 297 ms
51,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
    }
  }
}
0