結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー |
|
提出日時 | 2024-09-12 23:18:10 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 915 bytes |
コンパイル時間 | 2,517 ms |
コンパイル使用メモリ | 206,952 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-12 23:18:28 |
合計ジャッジ時間 | 3,744 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;bool is_kad(ll x,ll y,ll z){if(x==z)return 0;if(y>x&&y>z)return 1;if(y<x&&y<z)return 1;return 0;}int main() {cin.tie(nullptr);ios::sync_with_stdio(false);int T;cin>>T;for(int t=0;t<T;t++){ll N;cin>>N;vector<ll> A(N);for(int i=0;i<N;i++)cin>>A[i];ll an=0;for(int _=0;_<3;_++){rotate(A.begin(),A.begin()+1,A.end());vector<ll> DP(N+1,-1e18);DP[0]=DP[1]=DP[2]=0;for(int i=2;i<N;i++){ll nc=0;if(is_kad(A[i-2],A[i-1],A[i])){nc=A[i-2];}DP[i+1]=max(DP[i+1],DP[i-2]+nc);DP[i+1]=max(DP[i+1],DP[i]);}an=max(DP[N],an);}cout<<an<<endl;}}