結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー donutholedonuthole
提出日時 2021-01-29 21:54:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,063 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 108,724 KB
最終ジャッジ日時 2023-09-09 15:18:06
合計ジャッジ時間 4,042 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,728 KB
testcase_01 AC 93 ms
71,616 KB
testcase_02 AC 177 ms
79,640 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 179 ms
108,724 KB
testcase_06 WA -
testcase_07 AC 162 ms
108,148 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 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