結果
| 問題 | 
                            No.1368 サイクルの中に眠る門松列
                             | 
                    
| コンテスト | |
| ユーザー | 
                             hir355
                         | 
                    
| 提出日時 | 2021-01-29 21:34:28 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 191 ms / 2,000 ms | 
| コード長 | 643 bytes | 
| コンパイル時間 | 187 ms | 
| コンパイル使用メモリ | 82,688 KB | 
| 実行使用メモリ | 121,984 KB | 
| 最終ジャッジ日時 | 2024-06-27 07:42:53 | 
| 合計ジャッジ時間 | 3,310 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 15 | 
ソースコード
import sys
def is_kadomatsu(a, b, c):
    if a != b != c and a != c and (a < b > c or a > b < c):
        return True
    else:
        return False
input = sys.stdin.readline
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for _ in range(3):
        dp = [0] * (n + 1)
        for i in range(n):
            if i + 2 < n and is_kadomatsu(a[i], a[i + 1], a[i + 2]) and dp[i + 3] < dp[i] + a[i]:
                dp[i + 3] = dp[i] + a[i]
            if dp[i + 1] < dp[i]:
                dp[i + 1] = dp[i]
        ans = max(ans, dp[n])
        a = a[1:] + [a[0]]
    print(ans)
            
            
            
        
            
hir355