結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2021-01-29 22:00:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 1,499 ms
コンパイル使用メモリ 169,632 KB
実行使用メモリ 5,424 KB
最終ジャッジ日時 2023-09-09 15:23:39
合計ジャッジ時間 3,137 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 41 ms
4,380 KB
testcase_03 AC 9 ms
4,380 KB
testcase_04 AC 15 ms
4,380 KB
testcase_05 AC 60 ms
5,388 KB
testcase_06 AC 59 ms
5,388 KB
testcase_07 AC 61 ms
5,364 KB
testcase_08 AC 60 ms
5,424 KB
testcase_09 AC 44 ms
5,404 KB
testcase_10 AC 44 ms
5,364 KB
testcase_11 AC 45 ms
5,420 KB
testcase_12 AC 46 ms
5,392 KB
testcase_13 AC 45 ms
5,384 KB
testcase_14 AC 45 ms
5,328 KB
testcase_15 AC 45 ms
5,332 KB
権限があれば一括ダウンロードができます

ソースコード

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