結果

問題 No.971 いたずらっ子
ユーザー KodaiKodai
提出日時 2020-04-27 01:47:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 914 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 43,008 KB
最終ジャッジ日時 2024-04-29 22:29:18
合計ジャッジ時間 3,918 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 90 ms
15,528 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 30 ms
10,752 KB
testcase_12 AC 30 ms
10,880 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 31 ms
10,880 KB
testcase_17 AC 30 ms
10,624 KB
testcase_18 AC 30 ms
10,880 KB
testcase_19 AC 30 ms
10,752 KB
testcase_20 AC 30 ms
10,752 KB
testcase_21 AC 30 ms
10,752 KB
testcase_22 AC 30 ms
10,624 KB
testcase_23 AC 30 ms
10,624 KB
testcase_24 AC 29 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


dp_dict = {}


def solve(h, w):
    if h == H - 1 and w == W - 1:
        return 0

    if (h, w) not in dp_dict:
        if h == H - 1:
            temp = solve(h, w + 1) + 2 + h + w if a_list[h][w + 1] == "k" else solve(h, w + 1) + 1
            dp_dict[(h, w)] = temp
            return temp
        elif w == W - 1:
            temp = solve(h + 1, w) + 2 + h + w if a_list[h + 1][w] == "k" else solve(h + 1, w) + 1
            dp_dict[(h, w)] = temp
            return temp
        else:
            temp = min([solve(h + 1, w) + 2 + h + w if a_list[h + 1][w] == "k" else solve(h + 1, w) + 1,
                        solve(h, w + 1) + 2 + h + w if a_list[h][w + 1] == "k" else solve(h, w + 1) + 1])
            dp_dict[(h, w)] = temp
            return temp
    else:
        return dp_dict[(h, w)]


print(solve(0, 0))
0