結果

問題 No.971 いたずらっ子
ユーザー rlangevinrlangevin
提出日時 2023-07-12 12:24:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 615 ms / 2,000 ms
コード長 637 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 267,480 KB
最終ジャッジ日時 2023-10-12 02:32:28
合計ジャッジ時間 9,129 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 615 ms
267,448 KB
testcase_01 AC 575 ms
267,480 KB
testcase_02 AC 459 ms
220,080 KB
testcase_03 AC 479 ms
258,728 KB
testcase_04 AC 462 ms
255,912 KB
testcase_05 AC 478 ms
258,792 KB
testcase_06 AC 403 ms
225,204 KB
testcase_07 AC 102 ms
76,288 KB
testcase_08 AC 184 ms
119,980 KB
testcase_09 AC 183 ms
120,688 KB
testcase_10 AC 90 ms
75,968 KB
testcase_11 AC 75 ms
71,404 KB
testcase_12 AC 75 ms
71,496 KB
testcase_13 AC 82 ms
76,036 KB
testcase_14 AC 108 ms
78,140 KB
testcase_15 AC 78 ms
75,948 KB
testcase_16 AC 80 ms
71,268 KB
testcase_17 AC 76 ms
71,116 KB
testcase_18 AC 76 ms
71,360 KB
testcase_19 AC 76 ms
71,284 KB
testcase_20 AC 77 ms
71,424 KB
testcase_21 AC 75 ms
71,152 KB
testcase_22 AC 75 ms
71,120 KB
testcase_23 AC 75 ms
71,512 KB
testcase_24 AC 75 ms
71,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
A = []
for i in range(H):
    A.append(list(input()))

inf = 10 ** 18
dp = [[inf] * W for i in range(H)]
dp[0][0] = 0
for i in range(H):
    for j in range(W):
        if i != H - 1:
            if A[i + 1][j] == "k":
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + i + j + 1)
            else:
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
        if j != W - 1:
            if A[i][j + 1] == "k":
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + i + j + 1)
            else:
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j])

print(dp[H-1][W-1] + H + W - 2)
0