結果
問題 | No.971 いたずらっ子 |
ユーザー | Kodai |
提出日時 | 2020-04-27 01:50:59 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 954 bytes |
コンパイル時間 | 480 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 707,948 KB |
最終ジャッジ日時 | 2024-04-29 22:33:12 |
合計ジャッジ時間 | 7,383 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | MLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
ソースコード
import sys sys.setrecursionlimit(10**6) 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))