結果

問題 No.971 いたずらっ子
ユーザー stngstng
提出日時 2022-08-15 18:51:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 692 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 109,952 KB
最終ジャッジ日時 2024-04-25 02:18:56
合計ジャッジ時間 3,927 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 243 ms
109,604 KB
testcase_01 AC 249 ms
109,696 KB
testcase_02 AC 202 ms
92,664 KB
testcase_03 AC 184 ms
109,952 KB
testcase_04 AC 177 ms
109,692 KB
testcase_05 AC 180 ms
109,440 KB
testcase_06 AC 146 ms
92,164 KB
testcase_07 AC 54 ms
63,232 KB
testcase_08 AC 90 ms
83,272 KB
testcase_09 AC 92 ms
83,328 KB
testcase_10 AC 49 ms
60,288 KB
testcase_11 AC 38 ms
51,840 KB
testcase_12 AC 42 ms
51,712 KB
testcase_13 AC 45 ms
58,624 KB
testcase_14 AC 71 ms
69,760 KB
testcase_15 AC 45 ms
58,428 KB
testcase_16 AC 42 ms
53,248 KB
testcase_17 AC 39 ms
52,096 KB
testcase_18 AC 40 ms
52,096 KB
testcase_19 AC 39 ms
52,224 KB
testcase_20 AC 40 ms
51,968 KB
testcase_21 AC 43 ms
52,096 KB
testcase_22 AC 43 ms
52,608 KB
testcase_23 AC 40 ms
51,968 KB
testcase_24 AC 42 ms
52,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = map(int,input().split())
a = [input() for i in range(h)]

dp = [[10**9]*(w) for i in range(h)]
dp[0][0] = 0

for i in range(h):
    for j in range(w):
        if i+j == 0:
            continue
        if a[i][j] == "k":
            if i == 0:
                dp[i][j] = dp[i][j-1]+(i+j)+1
            elif j == 0:
                dp[i][j] = dp[i-1][j]+(i+j)+1
            else:
                dp[i][j] = min(dp[i-1][j],dp[i][j-1])+(i+j)+1
        else:
            if i == 0:
                dp[i][j] = dp[i][j-1]+1
            elif j == 0:
                dp[i][j] = dp[i-1][j]+1
            else:
                dp[i][j] = min(dp[i-1][j],dp[i][j-1])+1
#print(dp)
print(dp[h-1][w-1])
0