結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー どららどらら
提出日時 2021-01-29 21:46:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,008 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 170,332 KB
実行使用メモリ 6,264 KB
最終ジャッジ日時 2023-09-09 15:09:14
合計ジャッジ時間 3,500 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 49 ms
4,380 KB
testcase_03 AC 11 ms
4,380 KB
testcase_04 AC 18 ms
4,376 KB
testcase_05 AC 77 ms
6,196 KB
testcase_06 AC 77 ms
6,132 KB
testcase_07 AC 77 ms
6,152 KB
testcase_08 AC 77 ms
6,140 KB
testcase_09 AC 63 ms
6,184 KB
testcase_10 AC 63 ms
6,204 KB
testcase_11 AC 63 ms
6,256 KB
testcase_12 AC 62 ms
6,184 KB
testcase_13 AC 63 ms
6,216 KB
testcase_14 AC 64 ms
6,264 KB
testcase_15 AC 63 ms
6,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

bool is_kadomatsu(const vector<ll>& v){
  if(v[0] == v[1] || v[0] == v[2] || v[1] == v[2]) return false;
  if(v[0] < v[1] && v[1] > v[2]) return true;
  if(v[0] > v[1] && v[1] < v[2]) return true;
  return false;
}

void solve(){
  int N;
  cin >> N;
  vector<ll> v(N);
  rep(i,N) cin >> v[i];

  ll ret = 0;
  rep(i,3){
    vector<ll> dp(N+10, 0);
    rep(j,N-2){
      if(is_kadomatsu({v[j],v[j+1],v[j+2]})){
        dp[j+3] = max(dp[j+3], dp[j] + v[j]);
      }
      dp[j+1] = max(dp[j+1], dp[j]);
    }
    rep(j,dp.size()) ret = max(ret, dp[j]);
    rotate(v.begin(), v.begin()+1, v.end());
  }

  cout << ret << endl;
}

int main(){
  int T;
  cin >> T;
  rep(t,T){
    solve();
  }
  
  return 0;
}
0