結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー HaaHaa
提出日時 2021-01-29 21:50:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 922 bytes
コンパイル時間 1,640 ms
コンパイル使用メモリ 166,776 KB
実行使用メモリ 9,536 KB
最終ジャッジ日時 2023-09-09 15:13:27
合計ジャッジ時間 3,076 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 40 ms
4,376 KB
testcase_03 AC 9 ms
4,376 KB
testcase_04 AC 15 ms
4,380 KB
testcase_05 AC 68 ms
9,328 KB
testcase_06 AC 70 ms
9,284 KB
testcase_07 AC 67 ms
9,268 KB
testcase_08 AC 69 ms
9,220 KB
testcase_09 AC 54 ms
9,324 KB
testcase_10 AC 55 ms
9,456 KB
testcase_11 AC 55 ms
9,536 KB
testcase_12 AC 56 ms
9,424 KB
testcase_13 AC 56 ms
9,452 KB
testcase_14 AC 56 ms
9,324 KB
testcase_15 AC 53 ms
9,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=1e18;

bool kad(int a, int b, int c){
    if(a==c)
        return 0;
    if(a>b&&b<c)
        return 1;
    if(a<b&&b>c)
        return 1;
    return 0;
}

int main(){
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        VI a(n); REP(i,n) cin >> a[i];
        ll ans=0;
        REP(k,3){
            VI dp(n*3,0);
            REP(i,n-2){
                dp[k+i+3]=max(dp[k+i+3],dp[k+i+2]);
                if(kad(a[(k+i)%n],a[(k+i+1)%n],a[(k+i+2)%n])){
                    dp[k+i+3]=max(dp[k+i+3],dp[k+i]+a[(k+i)%n]);
                }
            }
            ans=max(ans,dp[k+n]);
        }
        cout << ans << endl;
    }
    return 0;
}
0