結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー ntuda
提出日時 2025-07-04 10:17:49
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 773 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 82,440 KB
実行使用メモリ 67,660 KB
最終ジャッジ日時 2025-07-04 10:17:52
合計ジャッジ時間 2,973 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 1
other RE * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

from atcoder.segtree import SegTree

for _ in range(int(input())):
    N = int(input())
    ST = SegTree(lambda x, y: x + y, 0, [0] * N)

    A = list(map(int, input().split()))
    dp = [0] * N
    dp2 = [0] * N
    for i in range(N):
        a, b, c = A[i], A[(i + 1) % N], A[(i + 2) % N]
        if a == b or b == c or c == a:
            add = 0
        elif (a < b and b < c) or (a > b and b > c):
            add = 0
        else:
            add = a
        dp[i] = add
    ans = 0
    for i in range(3):
        dp2 = [0] * (N - 2)
        for j in range(N - 2):
            if j < 3:
                dp2[j] = dp[(i + j) % N]
            else:
                dp2[j] = max(dp2[max(0, j - 5):j - 2]) + dp[(i + j) % N]
        ans = max(ans, max(dp2))
    print(ans)
0