結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー rlangevinrlangevin
提出日時 2023-01-15 11:46:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 523 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 107,716 KB
最終ジャッジ日時 2023-08-27 19:29:48
合計ジャッジ時間 5,482 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,404 KB
testcase_01 AC 69 ms
71,436 KB
testcase_02 AC 523 ms
85,728 KB
testcase_03 AC 193 ms
78,860 KB
testcase_04 AC 237 ms
81,352 KB
testcase_05 AC 189 ms
107,628 KB
testcase_06 AC 193 ms
107,260 KB
testcase_07 AC 179 ms
107,716 KB
testcase_08 AC 163 ms
107,492 KB
testcase_09 AC 257 ms
106,552 KB
testcase_10 AC 252 ms
106,464 KB
testcase_11 AC 259 ms
106,508 KB
testcase_12 AC 236 ms
106,592 KB
testcase_13 AC 257 ms
106,628 KB
testcase_14 AC 253 ms
106,472 KB
testcase_15 AC 251 ms
106,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

def kadomatsu(a, b, c):
    for i in [-1, 1]:
        if a * i < b * i and b * i > c * i and a != c:
            return True
    return False

def calc(A):
    N = len(A)
    inf = 10 ** 18
    dp = [-inf] * (N + 1)
    dp[0] = 0
    for i in range(N):
        if i != N - 1:
            dp[i + 1] = max(dp[i + 1], dp[i])
        if i < N - 2: 
            if kadomatsu(A[i], A[i + 1], A[i + 2]):
                dp[i + 3] = max(dp[i + 3], dp[i] + A[i])
    return max(dp)
    
    

T = int(readline())
for _ in range(T):
    N = int(readline())
    A = list(map(int, readline().split()))
    ans = calc(A)
    a = A.pop(0)
    A.append(a)
    ans = max(ans, calc(A))
    a = A.pop(0)
    A.append(a)
    ans = max(ans, calc(A))
    print(ans)
0