結果

問題 No.971 いたずらっ子
ユーザー maspymaspy
提出日時 2020-03-03 15:23:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 427 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 138,368 KB
最終ジャッジ日時 2024-04-25 02:11:20
合計ジャッジ時間 3,988 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 242 ms
138,112 KB
testcase_01 AC 246 ms
138,368 KB
testcase_02 AC 202 ms
123,392 KB
testcase_03 AC 198 ms
137,984 KB
testcase_04 AC 172 ms
118,272 KB
testcase_05 AC 182 ms
137,984 KB
testcase_06 AC 160 ms
124,672 KB
testcase_07 AC 51 ms
62,848 KB
testcase_08 AC 86 ms
82,688 KB
testcase_09 AC 83 ms
82,816 KB
testcase_10 AC 45 ms
60,416 KB
testcase_11 AC 35 ms
52,224 KB
testcase_12 AC 38 ms
51,840 KB
testcase_13 AC 43 ms
58,368 KB
testcase_14 AC 52 ms
63,488 KB
testcase_15 AC 43 ms
58,112 KB
testcase_16 AC 37 ms
52,224 KB
testcase_17 AC 36 ms
52,096 KB
testcase_18 AC 35 ms
52,096 KB
testcase_19 AC 37 ms
51,968 KB
testcase_20 AC 35 ms
51,968 KB
testcase_21 AC 38 ms
52,352 KB
testcase_22 AC 37 ms
52,480 KB
testcase_23 AC 36 ms
51,840 KB
testcase_24 AC 36 ms
51,840 KB
権限があれば一括ダウンロードができます

ソースコード

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