結果

問題 No.971 いたずらっ子
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-25 17:45:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 624 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 111,744 KB
最終ジャッジ日時 2024-04-25 02:17:13
合計ジャッジ時間 3,993 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 263 ms
111,616 KB
testcase_01 AC 263 ms
111,632 KB
testcase_02 AC 211 ms
98,048 KB
testcase_03 AC 201 ms
111,744 KB
testcase_04 AC 178 ms
94,184 KB
testcase_05 AC 178 ms
93,056 KB
testcase_06 AC 157 ms
97,468 KB
testcase_07 AC 58 ms
63,616 KB
testcase_08 AC 99 ms
84,864 KB
testcase_09 AC 97 ms
84,480 KB
testcase_10 AC 52 ms
60,672 KB
testcase_11 AC 41 ms
52,096 KB
testcase_12 AC 41 ms
52,096 KB
testcase_13 AC 47 ms
58,624 KB
testcase_14 AC 60 ms
64,640 KB
testcase_15 AC 47 ms
58,496 KB
testcase_16 AC 43 ms
52,352 KB
testcase_17 AC 42 ms
51,968 KB
testcase_18 AC 41 ms
52,096 KB
testcase_19 AC 42 ms
52,224 KB
testcase_20 AC 41 ms
52,224 KB
testcase_21 AC 42 ms
52,096 KB
testcase_22 AC 42 ms
52,096 KB
testcase_23 AC 41 ms
51,968 KB
testcase_24 AC 42 ms
51,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**9

H, W = map(int, input().split())
G = [input().rstrip() for _ in range(H)]

dp = [[inf] * W for _ in range(H)]
dp[0][0] = 0
for i in range(H):
    for j in range(W):
        if G[i][j] == ".":
            if i:
                dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
            if j:
                dp[i][j] = min(dp[i][j], dp[i][j-1] + 1)
        else:
            if i:
                dp[i][j] = min(dp[i][j], dp[i-1][j] + i + j + 1)
            if j:
                dp[i][j] = min(dp[i][j], dp[i][j-1] + i + j + 1)

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