結果

問題 No.45 回転寿司
ユーザー MitI_7MitI_7
提出日時 2017-01-11 23:20:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 478 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 10,684 KB
実行使用メモリ 8,984 KB
最終ジャッジ日時 2023-08-23 08:32:38
合計ジャッジ時間 2,070 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
8,652 KB
testcase_01 AC 22 ms
8,752 KB
testcase_02 AC 21 ms
8,900 KB
testcase_03 AC 21 ms
8,776 KB
testcase_04 AC 20 ms
8,632 KB
testcase_05 AC 18 ms
8,536 KB
testcase_06 AC 20 ms
8,732 KB
testcase_07 AC 21 ms
8,908 KB
testcase_08 AC 20 ms
8,616 KB
testcase_09 AC 21 ms
8,732 KB
testcase_10 AC 20 ms
8,608 KB
testcase_11 AC 20 ms
8,544 KB
testcase_12 AC 21 ms
8,792 KB
testcase_13 AC 19 ms
8,524 KB
testcase_14 AC 18 ms
8,452 KB
testcase_15 AC 20 ms
8,708 KB
testcase_16 AC 20 ms
8,520 KB
testcase_17 AC 19 ms
8,520 KB
testcase_18 AC 19 ms
8,576 KB
testcase_19 AC 21 ms
8,724 KB
testcase_20 AC 19 ms
8,460 KB
testcase_21 AC 19 ms
8,588 KB
testcase_22 AC 18 ms
8,568 KB
testcase_23 AC 19 ms
8,372 KB
testcase_24 AC 18 ms
8,616 KB
testcase_25 AC 18 ms
8,536 KB
testcase_26 AC 19 ms
8,704 KB
testcase_27 AC 20 ms
8,708 KB
testcase_28 AC 20 ms
8,604 KB
testcase_29 AC 20 ms
8,764 KB
testcase_30 AC 20 ms
8,864 KB
testcase_31 AC 18 ms
8,452 KB
testcase_32 AC 18 ms
8,516 KB
testcase_33 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

memo = {}


def dfs(i, pre_use):
    if i == len(value_list):
        return 0

    if (i, pre_use) in memo:
        return memo[(i, pre_use)]

    ans = 0
    ans = max(ans, dfs(i + 1, False))
    if not pre_use:
        ans = max(ans, dfs(i + 1, True) + value_list[i])

    memo[(i, pre_use)] = ans
    return ans


if __name__ == '__main__':
    n = int(input())
    value_list = list(map(int, input().split()))
    print(dfs(0, False))

0