結果

問題 No.971 いたずらっ子
ユーザー ああいいああいい
提出日時 2022-01-01 15:58:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 337 ms / 2,000 ms
コード長 574 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 110,464 KB
最終ジャッジ日時 2024-04-25 02:18:36
合計ジャッジ時間 4,412 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 336 ms
110,464 KB
testcase_01 AC 337 ms
110,208 KB
testcase_02 AC 284 ms
103,824 KB
testcase_03 AC 228 ms
109,696 KB
testcase_04 AC 224 ms
109,824 KB
testcase_05 AC 221 ms
109,952 KB
testcase_06 AC 184 ms
92,416 KB
testcase_07 AC 76 ms
70,784 KB
testcase_08 AC 111 ms
82,944 KB
testcase_09 AC 109 ms
83,328 KB
testcase_10 AC 56 ms
62,592 KB
testcase_11 AC 41 ms
51,840 KB
testcase_12 AC 40 ms
51,840 KB
testcase_13 AC 47 ms
58,752 KB
testcase_14 AC 78 ms
71,424 KB
testcase_15 AC 46 ms
58,496 KB
testcase_16 AC 45 ms
53,120 KB
testcase_17 AC 40 ms
51,840 KB
testcase_18 AC 42 ms
51,968 KB
testcase_19 AC 42 ms
51,584 KB
testcase_20 AC 41 ms
51,584 KB
testcase_21 AC 42 ms
52,096 KB
testcase_22 AC 40 ms
52,224 KB
testcase_23 AC 39 ms
51,840 KB
testcase_24 AC 40 ms
51,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

C = 10 ** 8
dp = [[C] * W for _ in range(H)]
dp[0][0] = 0
for h in range(H):
    for w in range(W):
        if w < W - 1:
            if a[h][w+1] == 'k':
                count = 1 + h + w + 1
            else:
                count = 1
            dp[h][w+1] = min(dp[h][w+1],dp[h][w] + count)
        if h < H - 1:
            if a[h+1][w] == 'k':
                count = 1 + h + w + 1
            else:
                count = 1
            dp[h+1][w] = min(dp[h+1][w],dp[h][w] + count)
print(dp[H-1][W-1])
0