結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー roarisroaris
提出日時 2021-03-02 16:02:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 431 ms / 2,000 ms
コード長 607 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 82,468 KB
実行使用メモリ 106,948 KB
最終ジャッジ日時 2024-04-14 04:41:42
合計ジャッジ時間 4,484 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,544 KB
testcase_01 AC 42 ms
55,568 KB
testcase_02 AC 431 ms
84,104 KB
testcase_03 AC 164 ms
78,984 KB
testcase_04 AC 226 ms
79,008 KB
testcase_05 AC 174 ms
106,812 KB
testcase_06 AC 173 ms
106,588 KB
testcase_07 AC 141 ms
106,948 KB
testcase_08 AC 188 ms
106,816 KB
testcase_09 AC 237 ms
105,452 KB
testcase_10 AC 216 ms
105,936 KB
testcase_11 AC 211 ms
105,580 KB
testcase_12 AC 206 ms
105,484 KB
testcase_13 AC 208 ms
105,376 KB
testcase_14 AC 214 ms
105,624 KB
testcase_15 AC 234 ms
105,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

def calc(A):
    dp = [0]*(N+1)
    
    for i in range(2, N):
        dp[i+1] = dp[i]
        
        if len({A[i-2], A[i-1], A[i]})==3 and A[i-1] in [min(A[i-2], A[i-1], A[i]), max(A[i-2], A[i-1], A[i])]:
            dp[i+1] = max(dp[i+1], dp[i-2]+A[i-2])
    
    return dp[N]

for _ in range(int(input())):
    N = int(input())
    A = list(map(int, input().split()))
    ans = calc(A)
    A = deque(A)
    A.append(A.popleft())
    ans = max(ans, calc(list(A)))
    A.append(A.popleft())
    ans = max(ans, calc(list(A)))
    print(ans)
0