結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー ShibuyapShibuyap
提出日時 2021-02-06 08:04:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,151 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 198,988 KB
実行使用メモリ 9,748 KB
最終ジャッジ日時 2023-09-15 12:46:39
合計ジャッジ時間 3,731 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 40 ms
4,380 KB
testcase_03 AC 9 ms
4,376 KB
testcase_04 AC 15 ms
4,380 KB
testcase_05 AC 64 ms
9,720 KB
testcase_06 AC 64 ms
9,612 KB
testcase_07 AC 65 ms
9,552 KB
testcase_08 AC 66 ms
9,552 KB
testcase_09 AC 49 ms
9,748 KB
testcase_10 AC 48 ms
9,612 KB
testcase_11 AC 49 ms
9,588 KB
testcase_12 AC 49 ms
9,576 KB
testcase_13 AC 48 ms
9,720 KB
testcase_14 AC 48 ms
9,564 KB
testcase_15 AC 49 ms
9,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005

int isKadomatsu(int x, int y, int z){
    int res = 0;
    if(y < x && y < z && x != z) res = 1;
    if(y > x && y > z && x != z) res = 1;
    return res;
}

int main() {
    int T; cin >> T;
    rep(_,T){
        int n; cin >> n;
        ll b[n*2];
        rep(i,n){
            cin >> b[i];
            b[i+n] = b[i];
        }
        ll ans = 0;
        rep(loop, 3){
            ll a[n];
            rep(i,n){
                a[i] = b[i+loop];
            }
            ll dp[n] = {};
            srep(i,2,n){
                dp[i] = dp[i-1];
                if(isKadomatsu(a[i-2],a[i-1],a[i])){
                    if(i == 2) dp[i] = a[i-2];
                    else dp[i] = max(dp[i], dp[i-3] + a[i-2]);
                }
            }
            ans = max(ans, dp[n-1]);
        }
        cout << ans << endl;
    }
    return 0;
}
 
 
0