結果

問題 No.45 回転寿司
ユーザー けむけむけむけむ
提出日時 2021-06-17 15:19:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 579 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 13,104 KB
最終ジャッジ日時 2023-08-30 22:45:55
合計ジャッジ時間 2,468 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
9,556 KB
testcase_01 AC 30 ms
10,204 KB
testcase_02 AC 39 ms
11,596 KB
testcase_03 AC 43 ms
12,160 KB
testcase_04 AC 31 ms
10,508 KB
testcase_05 AC 20 ms
8,684 KB
testcase_06 AC 28 ms
9,892 KB
testcase_07 AC 39 ms
11,704 KB
testcase_08 AC 22 ms
9,124 KB
testcase_09 AC 41 ms
11,872 KB
testcase_10 AC 25 ms
9,464 KB
testcase_11 AC 21 ms
8,952 KB
testcase_12 AC 40 ms
11,948 KB
testcase_13 AC 19 ms
8,808 KB
testcase_14 AC 19 ms
8,676 KB
testcase_15 AC 26 ms
9,608 KB
testcase_16 AC 22 ms
9,076 KB
testcase_17 AC 24 ms
9,424 KB
testcase_18 AC 23 ms
9,216 KB
testcase_19 AC 35 ms
11,196 KB
testcase_20 AC 19 ms
8,640 KB
testcase_21 AC 19 ms
8,608 KB
testcase_22 AC 19 ms
8,664 KB
testcase_23 AC 19 ms
8,608 KB
testcase_24 AC 18 ms
8,580 KB
testcase_25 AC 19 ms
8,676 KB
testcase_26 AC 26 ms
9,640 KB
testcase_27 AC 35 ms
11,136 KB
testcase_28 AC 27 ms
9,860 KB
testcase_29 AC 33 ms
10,772 KB
testcase_30 AC 34 ms
10,756 KB
testcase_31 AC 19 ms
8,688 KB
testcase_32 AC 19 ms
8,684 KB
testcase_33 AC 48 ms
13,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache
import sys

sys.setrecursionlimit(1500)

@lru_cache(maxsize=1000)
def osusi(N, V):
    if N == 1:
        return V[0]
    pat = [0, 0, 0, 0, V[-2], V[-1]]
    if N - 2 >= 1:
        pat[0] = osusi(N - 2, V[:N - 2]) + V[-1]
    if N - 3 >= 1:
        pat[1] = osusi(N - 3, V[:N - 3]) + V[-1]
        pat[2] = osusi(N - 3, V[:N - 3]) + V[-2]
    if N - 4 >= 1:
        pat[3] = osusi(N - 4, V[:N - 4]) + V[-2]
    return max(pat)

if __name__ == '__main__':
    N = int(input())
    V_li = tuple(map(int, input().split()))
    print(osusi(N, V_li))
0