結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー umezoumezo
提出日時 2021-01-29 22:43:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,340 bytes
コンパイル時間 2,330 ms
コンパイル使用メモリ 204,400 KB
実行使用メモリ 17,160 KB
最終ジャッジ日時 2023-09-09 16:20:17
合計ジャッジ時間 3,944 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 44 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 73 ms
17,088 KB
testcase_06 AC 73 ms
16,976 KB
testcase_07 AC 73 ms
17,016 KB
testcase_08 AC 73 ms
17,088 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

bool iskado(ll x,ll y,ll z){
  if(y>x && y>z && x!=z) return true;
  if(y<x && y<z && x!=z) return true;
  return false;
}

int main(){
  int t;
  cin>>t;
  
  while(t--){
    int n;
    cin>>n;
    
    vector<ll> A(n),B(n),C(n);
    rep(i,n){
      ll x;
      cin>>x;
      A[i]=x;
      B[(i+1)%n]=x;
      C[(i+2)%n]=x;
    }
    
    vector<ll> dpa(n),dpb(n),dpc(n);
    vector<ll> maa(n),mab(n),mac(n);
    
    for(int i=0;i<n-2;i++){
      if(iskado(A[i],A[i+1],A[i+2])==false) continue;
      if(i<3) dpa[i]=A[i];
      else dpa[i]=maa[i-3]+A[i];
      if(i==0) maa[i]=dpa[i];
      else maa[i]=max(maa[i-1],dpa[i]);
    }
    for(int i=0;i<n-2;i++){
      if(iskado(B[i],B[i+1],B[i+2])==false) continue;
      if(i<3) dpb[i]=B[i];
      else dpb[i]=mab[i-3]+B[i];
      if(i==0) mab[i]=dpb[i];
      else mab[i]=max(mab[i-1],dpb[i]);
    }
    for(int i=0;i<n-2;i++){
      if(iskado(C[i],C[i+1],C[i+2])==false) continue;
      if(i<3) dpc[i]=C[i];
      else dpc[i]=mac[i-3]+C[i];
      if(i==0) mac[i]=dpc[i];
      else mac[i]=max(mac[i-1],dpc[i]);
    }
    
    ll ans=0;
    rep(i,n-2){
      ans=max({ans,dpa[i],dpb[i],dpc[i]});
    }
    cout<<ans<<endl;
  }

  return 0;
}
0