結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー donuthole
提出日時 2021-01-29 21:54:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,063 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 82,092 KB
実行使用メモリ 106,396 KB
最終ジャッジ日時 2024-06-27 08:08:11
合計ジャッジ時間 2,926 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import collections
import bisect


# sys.setrecursionlimit(10000001)
INF = 10 ** 20
# MOD = 10 ** 9 + 7
MOD = 998244353


def ni(): return int(sys.stdin.buffer.readline())
def ns(): return map(int, sys.stdin.buffer.readline().split())
def na(): return list(map(int, sys.stdin.buffer.readline().split()))
def na1(): return list(map(lambda x: int(x)-1, sys.stdin.buffer.readline().split()))


# ===CODE===

def main():
    t = ni()
    for ti in range(t):
        n = ni()
        a = na()

        flg = [False]*n
        for i in range(n):
            nxt = (i+1) % n
            nnxt = (i+2) % n
            ta = [a[i], a[nxt], a[nnxt]]
            if len(set(ta)) == 3 and (ta[0] < ta[1] > ta[2] or ta[0] > ta[1] < ta[2]):
                flg[i] = True

        res = 0
        for i in range(3):
            dp = [0]*(n+3)
            for i in range(i, n-2+i):
                if flg[i]:
                    dp[i+3] = max(dp[i+3], dp[i]+a[i])
            res = max(res, max(dp))
        print(res)

if __name__ == '__main__':
    main()
0