結果

問題 No.971 いたずらっ子
ユーザー daku9640daku9640
提出日時 2020-01-20 03:37:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 575 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 111,888 KB
最終ジャッジ日時 2024-04-25 02:09:29
合計ジャッジ時間 3,500 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 203 ms
111,888 KB
testcase_01 AC 214 ms
111,644 KB
testcase_02 AC 175 ms
101,888 KB
testcase_03 AC 190 ms
111,744 KB
testcase_04 AC 187 ms
109,468 KB
testcase_05 AC 179 ms
111,840 KB
testcase_06 AC 153 ms
101,888 KB
testcase_07 AC 53 ms
62,844 KB
testcase_08 AC 84 ms
84,864 KB
testcase_09 AC 81 ms
84,352 KB
testcase_10 AC 46 ms
59,904 KB
testcase_11 AC 36 ms
51,968 KB
testcase_12 AC 36 ms
51,968 KB
testcase_13 AC 43 ms
58,368 KB
testcase_14 AC 56 ms
65,024 KB
testcase_15 AC 42 ms
58,496 KB
testcase_16 AC 37 ms
52,736 KB
testcase_17 AC 36 ms
51,840 KB
testcase_18 AC 40 ms
51,840 KB
testcase_19 AC 36 ms
52,224 KB
testcase_20 AC 40 ms
51,840 KB
testcase_21 AC 39 ms
52,096 KB
testcase_22 AC 40 ms
52,608 KB
testcase_23 AC 38 ms
52,480 KB
testcase_24 AC 36 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
INF = int(1e7)
def solve():
    H, W = map(int, input().split())
    dp = [[INF] * (W + 2) for _ in range(H + 2)]
    dp[0][1] = -1
    A = ["#" * (W + 2)] + ["#" + readline().rstrip("\n") + "#" for _ in range(H)] + ["#" * (W + 2)]
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if A[i][j] == ".":
                dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1
            elif A[i][j] == "k":
                dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + (i - 1) + (j - 1) + 1
    print(dp[H][W])
solve()
0