結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー 🍮かんプリン
提出日時 2021-01-29 22:00:42
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 171,212 KB
実行使用メモリ 5,724 KB
最終ジャッジ日時 2024-06-27 08:13:29
合計ジャッジ時間 3,020 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.01.29 22:00:36
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

bool kadomatsu(int a,int b,int c) {
    
    return a != c && ((a < b && b > c) || (a > b && b < c));
}
int main() {
    int t;cin >> t;
    while(t--) {
        int n;cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        ll ans = 0;
        for (int k = 0; k < 3; k++) {
            vector<ll> dp(n+1);
            for (int i = 2; i < n; i++) {
                if (kadomatsu(a[i-2],a[i-1],a[i])) {
                    dp[i+1] = max(dp[i-2]+a[i-2],dp[i]);
                    
                }
                else dp[i+1] = dp[i];
                
            }
            
            ans = max(ans,dp[n]);
            rotate(a.begin(), a.begin()+1,a.end());
            
        }
        cout << ans << endl;
    }
    return 0;
}
0