結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー donutholedonuthole
提出日時 2021-01-29 22:00:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,110 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 86,856 KB
実行使用メモリ 108,680 KB
最終ジャッジ日時 2023-09-09 15:22:53
合計ジャッジ時間 4,519 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,632 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 186 ms
108,680 KB
testcase_06 WA -
testcase_07 AC 166 ms
108,428 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

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 j in range(i, n-2+i):
                if flg[j]:
                    dp[j+3] = max(dp[j+3], dp[j]+a[i])
                dp[j+1] = max(dp[j+1], dp[j])
            res = max(res, max(dp))
        print(res)


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