結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー auauaauaua
提出日時 2021-01-30 14:13:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,888 bytes
コンパイル時間 1,647 ms
コンパイル使用メモリ 170,960 KB
実行使用メモリ 9,532 KB
最終ジャッジ日時 2023-09-10 10:42:21
合計ジャッジ時間 3,941 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 42 ms
4,376 KB
testcase_03 AC 10 ms
4,376 KB
testcase_04 AC 15 ms
4,376 KB
testcase_05 AC 68 ms
9,392 KB
testcase_06 AC 68 ms
9,468 KB
testcase_07 AC 68 ms
9,396 KB
testcase_08 AC 69 ms
9,292 KB
testcase_09 AC 52 ms
9,188 KB
testcase_10 AC 51 ms
9,392 KB
testcase_11 AC 52 ms
9,152 KB
testcase_12 AC 51 ms
9,532 KB
testcase_13 AC 52 ms
9,528 KB
testcase_14 AC 52 ms
9,344 KB
testcase_15 AC 52 ms
9,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll inf=INF*INF;
const ll mod=998244353;
const ll MAX=100010;


bool is_k(ll a,ll b,ll c){
    bool f=0;
    if((a>b&&c>b)||(a<b&&c<b))f=1;
    if(a==b||b==c||c==a)f=0;
    return f;
}

signed main(){
    ll t;cin>>t;
    while(t--){
        ll n;cin>>n;
        vector<ll>a(n);
        rep(i,n){
            cin>>a[i];
            a.pb(a[i]);
        }
        ll ans=0;
        {
            vector<ll>dp(2*n);
            if(is_k(a[0],a[1],a[2]))dp[2]=a[0];
            REP(i,3,n){
                if(is_k(a[i-2],a[i-1],a[i])){
                    dp[i]=dp[i-3]+a[i-2];
                }
                dp[i]=max(dp[i-1],dp[i]);
            }
            ans=max(dp[n-1],ans);
        }
        {
            vector<ll>dp(2*n);
            if(is_k(a[1],a[2],a[3]))dp[3]=a[1];
            REP(i,4,n+1){
                if(is_k(a[i-2],a[i-1],a[i])){
                    dp[i]=dp[i-3]+a[i-2];
                }
                dp[i]=max(dp[i-1],dp[i]);
            }
            ans=max(dp[n],ans);
        }
        {
            vector<ll>dp(2*n);
            if(is_k(a[2],a[3],a[4]))dp[4]=a[2];
            REP(i,5,n+2){
                if(is_k(a[i-2],a[i-1],a[i])){
                    dp[i]=dp[i-3]+a[i-2];
                }
                dp[i]=max(dp[i-1],dp[i]);
            }
            ans=max(dp[n+1],ans);
        }
        cout<<ans<<endl;
    }
}
0