結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー 👑 PCTprobabilityPCTprobability
提出日時 2021-01-29 21:33:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,669 bytes
コンパイル時間 1,972 ms
コンパイル使用メモリ 204,196 KB
実行使用メモリ 9,400 KB
最終ジャッジ日時 2023-09-09 14:48:36
合計ジャッジ時間 3,340 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 26 ms
9,324 KB
testcase_06 AC 26 ms
9,268 KB
testcase_07 AC 26 ms
9,400 KB
testcase_08 WA -
testcase_09 AC 24 ms
9,332 KB
testcase_10 AC 23 ms
9,364 KB
testcase_11 AC 23 ms
9,344 KB
testcase_12 AC 24 ms
9,344 KB
testcase_13 WA -
testcase_14 AC 24 ms
9,316 KB
testcase_15 AC 24 ms
9,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using ld = long double;
#define all(s) (s).begin(),(s).end()
#define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i]
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
#define SIZE(n) int(n.size())
#define P pair<ll,ll>
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
ll modPow(ll a, ll n, ll modulo) { ll ret = 1; ll p = a % modulo; while (n) { if (n & 1) ret = ret * p % modulo; p = p * p % modulo; n >>= 1; } return ret; }
bool check(ll a,ll b,ll c){
  if((a-b)*(c-b)>0&&a!=c&&b!=c&&a!=b){
    return true;
  }
  return false;
}
void solve(){
  ll n;
  cin>>n;
  vector<ll> a(n);
  vcin(a);
  vector<bool> t(n);
  vector<ll> b(2*n);
  for(int i=0;i<n;i++){
    b[i]=a[i];
    b[i+n]=a[i];
  }
  for(int i=0;i<n;i++){
    t[i]=check(b[i],b[i+1],b[i+2]);
  }
  vector<ll> dp(n+3,0);
  ll m=0;
  for(int i=0;i<n;i++){
    if(t[i]){
      dp[i]=m+a[i];
   //   cout<<"A";
    }
    else{
      dp[i]=m;
   //   cout<<"B";
    }
    if(i>=2){
      chmax(m,dp[i-2]);
    }
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    chmax(ans,dp[i]);
  }
  cout<<ans<<endl;
}
int main() {
  /* mod は 1e9+7 */
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(10);
  ll a;
  cin>>a;
  while(a--){
    solve();
  }
}
0