結果
問題 |
No.1368 サイクルの中に眠る門松列
|
ユーザー |
|
提出日時 | 2021-02-01 15:03:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 1,228 bytes |
コンパイル時間 | 2,012 ms |
コンパイル使用メモリ | 199,792 KB |
最終ジャッジ日時 | 2025-01-18 10:35:45 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int q; cin >> q; while(q--){ int n; cin >> n; vector<ll> a(n); for(int i=0;i<n;i++){ cin >> a[i]; } ll res=0; auto ok=[&](int i)->bool{ if(i-1<0 or i+1>=n)return false; if(a[i]==a[i-1] or a[i-1]==a[i+1] or a[i+1]==a[i])return false; if(a[i]>a[i-1] and a[i]>a[i+1])return true; if(a[i]<a[i-1] and a[i]<a[i+1])return true; return false; }; for(int _=0;_<3;_++){ vector<ll> dp(n+1); for(int i=0;i<n;i++){ if(ok(i)){ dp[i+2]=max(dp[i+2],dp[i-1]+a[i-1]); } if(i){ dp[i+1]=max(dp[i+1],dp[i]); } } res=max(res,*max_element(dp.begin(), dp.end())); rotate(a.begin(), a.begin()+1, a.end()); } cout << res << "\n"; } }