結果
問題 |
No.1368 サイクルの中に眠る門松列
|
ユーザー |
![]() |
提出日時 | 2021-02-09 20:31:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 73 ms / 2,000 ms |
コード長 | 1,257 bytes |
コンパイル時間 | 1,063 ms |
コンパイル使用メモリ | 126,040 KB |
最終ジャッジ日時 | 2025-01-18 16:45:18 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <stack> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; bool is_kadomatsu(int a, int b, int c){ if(a==c) return false; if(a<b && b>c) return true; if(a>b && b<c) return true; return false; } int main() { int t; cin>>t; while(t--){ int n; cin>>n; vector<int> a(n+2); for(int i=0; i<n; i++){ cin>>a[i+2]; } for(int i=0; i<2; i++) a[i]=a[i+n]; ll ans=0; for(int p=0; p<3; p++){ vector<ll> dp(n+1); for(int i=3; i<=n; i++){ dp[i]=dp[i-1]; if(is_kadomatsu(a[i-3+p], a[i-2+p], a[i-1+p])){ dp[i]=max(dp[i-3]+a[i-3+p], dp[i]); } } ans=max(ans, dp[n]); } cout<<ans<<endl; } return 0; }