結果

問題 No.971 いたずらっ子
ユーザー NagisaNagisa
提出日時 2020-01-17 21:59:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 580 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 108,288 KB
最終ジャッジ日時 2024-04-25 02:00:57
合計ジャッジ時間 3,994 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 264 ms
107,392 KB
testcase_01 AC 262 ms
107,264 KB
testcase_02 AC 215 ms
91,392 KB
testcase_03 AC 195 ms
107,392 KB
testcase_04 AC 194 ms
108,288 KB
testcase_05 AC 194 ms
106,880 KB
testcase_06 AC 182 ms
90,752 KB
testcase_07 AC 60 ms
63,616 KB
testcase_08 AC 105 ms
81,408 KB
testcase_09 AC 102 ms
82,304 KB
testcase_10 AC 51 ms
60,288 KB
testcase_11 AC 42 ms
52,352 KB
testcase_12 AC 41 ms
52,096 KB
testcase_13 AC 47 ms
58,880 KB
testcase_14 AC 88 ms
74,112 KB
testcase_15 AC 47 ms
58,752 KB
testcase_16 AC 46 ms
53,504 KB
testcase_17 AC 41 ms
51,840 KB
testcase_18 AC 42 ms
51,968 KB
testcase_19 AC 44 ms
52,096 KB
testcase_20 AC 42 ms
52,352 KB
testcase_21 AC 43 ms
52,224 KB
testcase_22 AC 42 ms
52,224 KB
testcase_23 AC 44 ms
51,712 KB
testcase_24 AC 43 ms
52,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int,input().split())
P = [input() for k in range(H)]
G = [[0 for k in range(W)] for l in range(H)]

for x in range(1,W):
    if P[0][x] == "k":
        G[0][x] = G[0][x-1] + 1 + x
    else:
        G[0][x] = G[0][x-1] + 1

for y in range(1,H):
    if P[y][0] == "k":
        G[y][0] = G[y-1][0] + 1 + y
    else:
        G[y][0] = G[y-1][0] + 1



for y in range(1,H):
    for x in range(1,W):
        if P[y][x] == "k":
            G[y][x] = min(G[y][x-1]+(y+x)+1,G[y-1][x]+(y+x)+1)
        else:
            G[y][x] = min(G[y][x-1]+1,G[y-1][x]+1)

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