結果

問題 No.971 いたずらっ子
ユーザー maspymaspy
提出日時 2020-03-03 15:23:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 138,240 KB
最終ジャッジ日時 2024-11-07 11:42:10
合計ジャッジ時間 4,289 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
H, W = map(int, readline().split())
A = [list(readline().rstrip()) for _ in range(H)]

# %%
dp = [[10 ** 9] * W for _ in range(H)]
dp[0][0] = 0
for h in range(H):
    for w in range(W):
        if h > 0:
            x = dp[h - 1][w] + 1
            if dp[h][w] > x:
                dp[h][w] = x
        if w > 0:
            x = dp[h][w - 1] + 1
            if dp[h][w] > x:
                dp[h][w] = x
        if A[h][w] == ord('k'):
            dp[h][w] += (h + w)

# %%
print(dp[-1][-1])
0