結果

問題 No.971 いたずらっ子
ユーザー KodaiKodai
提出日時 2020-04-27 13:12:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 817 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 266,752 KB
最終ジャッジ日時 2024-04-25 02:13:44
合計ジャッジ時間 8,376 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 817 ms
266,752 KB
testcase_01 AC 803 ms
266,496 KB
testcase_02 AC 571 ms
218,836 KB
testcase_03 AC 753 ms
266,652 KB
testcase_04 AC 651 ms
255,232 KB
testcase_05 AC 761 ms
266,496 KB
testcase_06 AC 569 ms
223,324 KB
testcase_07 AC 73 ms
77,232 KB
testcase_08 AC 249 ms
125,824 KB
testcase_09 AC 234 ms
123,520 KB
testcase_10 AC 68 ms
77,420 KB
testcase_11 AC 43 ms
51,584 KB
testcase_12 AC 42 ms
52,096 KB
testcase_13 AC 52 ms
59,264 KB
testcase_14 AC 96 ms
76,928 KB
testcase_15 AC 49 ms
59,136 KB
testcase_16 AC 48 ms
53,888 KB
testcase_17 AC 42 ms
51,968 KB
testcase_18 AC 42 ms
51,968 KB
testcase_19 AC 42 ms
51,712 KB
testcase_20 AC 41 ms
51,840 KB
testcase_21 AC 42 ms
52,224 KB
testcase_22 AC 43 ms
52,096 KB
testcase_23 AC 42 ms
51,968 KB
testcase_24 AC 42 ms
52,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = list(map(int, input().split()))
a_list = [[s for s in input()] for i in range(H)]

dp_list = [[0 for i in range(W)] for j in range(H)]

for h in range(H):
    for w in range(W):
        if h > 0 and w > 0:
            dp_list[h][w] = min([dp_list[h - 1][w], dp_list[h][w - 1]])
            dp_list[h][w] += (1 + h + w) if a_list[h][w] == "k" else 1
        elif h > 0:
            dp_list[h][w] = dp_list[h - 1][w]
            dp_list[h][w] += (1 + h + w) if a_list[h][w] == "k" else 1
        elif w > 0:
            dp_list[h][w] = dp_list[h][w - 1]
            dp_list[h][w] += (1 + h + w) if a_list[h][w] == "k" else 1
        else:
            continue
print(dp_list[-1][-1])
0