結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー ocvret_ocvret_
提出日時 2021-01-29 22:09:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 961 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 170,272 KB
実行使用メモリ 5,384 KB
最終ジャッジ日時 2023-09-09 15:33:12
合計ジャッジ時間 3,408 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 43 ms
4,376 KB
testcase_03 AC 9 ms
4,376 KB
testcase_04 AC 15 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 61 ms
5,264 KB
testcase_08 WA -
testcase_09 AC 49 ms
5,316 KB
testcase_10 AC 48 ms
5,384 KB
testcase_11 AC 48 ms
5,312 KB
testcase_12 AC 48 ms
5,196 KB
testcase_13 AC 48 ms
5,188 KB
testcase_14 AC 48 ms
5,340 KB
testcase_15 AC 48 ms
5,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>

using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  int T;
  cin >> T;
  while(T--){
    int n;cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    rep(i,3)a.push_back(a[i]);
    auto solve = [&](int s){
      vector<ll> dp(n+10);
      for(int i = s+2;i < n+s;i++){
        dp[i] = max(dp[i],dp[i-1]);
        int k = 0;
        if(i-3 >= 0)k = dp[i-3];
        if(a[i-2] != a[i-1] && a[i-1] != a[i] && a[i-2] != a[i] && (*min_element(a.begin()+i-2,a.begin()+i+1) == a[i-1] || *max_element(a.begin()+i-2,a.begin()+i+1) == a[i-1])){
          dp[i] = max(dp[i],1ll*k + a[i-2]);
        }
      }
      return dp[n+s-1];
    };
    cout << max({solve(0),solve(1),solve(2)}) << "\n";
  }
  

  return 0;
}
0