結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー 👑 NachiaNachia
提出日時 2021-01-29 22:00:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 1,820 ms
コンパイル使用メモリ 199,936 KB
実行使用メモリ 6,192 KB
最終ジャッジ日時 2023-09-09 15:23:53
合計ジャッジ時間 3,082 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 13 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 27 ms
6,080 KB
testcase_06 AC 26 ms
6,012 KB
testcase_07 AC 26 ms
6,136 KB
testcase_08 AC 26 ms
6,060 KB
testcase_09 AC 24 ms
6,056 KB
testcase_10 AC 25 ms
6,072 KB
testcase_11 AC 25 ms
6,192 KB
testcase_12 AC 25 ms
5,988 KB
testcase_13 AC 25 ms
5,992 KB
testcase_14 AC 25 ms
6,060 KB
testcase_15 AC 25 ms
6,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

bool iskadomatsu(int a,int b,int c){
  if(a==b||b==c||a==c) return false;
  return ((a<b&&c<b)||(a>b&&c>b));
}

int N;
int A[200004];
bool K[200002];
LL dp[200005];

void loop(){
  scanf("%d",&N);
  rep(i,N) scanf("%d",&A[i]);
  rep(i,4) A[N+i]=A[i];
  rep(i,N+2) K[i]=iskadomatsu(A[i],A[i+1],A[i+2]);
  LL ans=0;
  rep(s,3){
    rep(i,N+5) dp[i]=0;
    rep(i,N){
      dp[i+1]=max(dp[i+1],dp[i]);
      if(K[i+s]) dp[i+3]=max(dp[i+3],dp[i]+A[i+s]);
    }
    ans=max(ans,dp[N]);
  }
  printf("%lld\n",ans);
}

int main(){
  int T; scanf("%d",&T);
  while(T--) loop();
  return 0;
}
0