結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
9,472 KB
testcase_01 AC 32 ms
10,196 KB
testcase_02 AC 41 ms
11,720 KB
testcase_03 AC 44 ms
12,220 KB
testcase_04 AC 32 ms
10,412 KB
testcase_05 AC 20 ms
8,652 KB
testcase_06 AC 29 ms
9,920 KB
testcase_07 AC 40 ms
11,664 KB
testcase_08 AC 23 ms
9,072 KB
testcase_09 AC 42 ms
12,068 KB
testcase_10 AC 26 ms
9,388 KB
testcase_11 AC 21 ms
9,040 KB
testcase_12 AC 41 ms
11,888 KB
testcase_13 AC 19 ms
8,640 KB
testcase_14 AC 19 ms
8,592 KB
testcase_15 AC 27 ms
9,572 KB
testcase_16 AC 23 ms
9,160 KB
testcase_17 AC 26 ms
9,416 KB
testcase_18 AC 23 ms
9,168 KB
testcase_19 AC 36 ms
11,120 KB
testcase_20 AC 20 ms
8,708 KB
testcase_21 AC 20 ms
8,580 KB
testcase_22 AC 20 ms
8,608 KB
testcase_23 AC 19 ms
8,548 KB
testcase_24 AC 19 ms
8,496 KB
testcase_25 AC 19 ms
8,548 KB
testcase_26 AC 27 ms
9,684 KB
testcase_27 AC 36 ms
11,096 KB
testcase_28 AC 27 ms
9,584 KB
testcase_29 AC 34 ms
10,788 KB
testcase_30 AC 35 ms
10,808 KB
testcase_31 AC 19 ms
8,576 KB
testcase_32 AC 19 ms
8,604 KB
testcase_33 AC 49 ms
13,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache
import sys

sys.setrecursionlimit(2000)

@lru_cache(maxsize=5000)
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