結果

問題 No.971 いたずらっ子
ユーザー roarisroaris
提出日時 2020-01-18 20:35:31
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 430 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 112,764 KB
最終ジャッジ日時 2023-08-07 08:02:23
合計ジャッジ時間 4,914 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 264 ms
112,764 KB
testcase_01 AC 264 ms
112,692 KB
testcase_02 AC 216 ms
97,316 KB
testcase_03 AC 213 ms
112,708 KB
testcase_04 AC 191 ms
93,512 KB
testcase_05 AC 206 ms
112,524 KB
testcase_06 AC 174 ms
96,800 KB
testcase_07 AC 83 ms
76,108 KB
testcase_08 AC 112 ms
86,588 KB
testcase_09 AC 112 ms
85,868 KB
testcase_10 AC 78 ms
75,964 KB
testcase_11 AC 69 ms
71,240 KB
testcase_12 AC 69 ms
71,364 KB
testcase_13 AC 74 ms
75,868 KB
testcase_14 AC 83 ms
76,812 KB
testcase_15 AC 74 ms
76,108 KB
testcase_16 AC 70 ms
71,240 KB
testcase_17 AC 69 ms
71,084 KB
testcase_18 AC 69 ms
71,168 KB
testcase_19 AC 70 ms
71,208 KB
testcase_20 AC 69 ms
71,088 KB
testcase_21 AC 69 ms
71,364 KB
testcase_22 AC 70 ms
71,164 KB
testcase_23 AC 70 ms
71,124 KB
testcase_24 AC 69 ms
71,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

H, W = map(int, input().split())
a = [input()[:-1] for _ in range(H)]
dp = [[10**18]*W for _ in range(H)]
dp[0][0] = 0

for i in range(H):
    for j in range(W):
        if i>0:
            dp[i][j] = min(dp[i][j], dp[i-1][j]+(1 if a[i][j]=='.' else i+j+1))
            
        if j>0:
            dp[i][j] = min(dp[i][j], dp[i][j-1]+(1 if a[i][j]=='.' else i+j+1))
    
print(dp[H-1][W-1])
0