結果
問題 | No.209 Longest Mountain Subsequence |
ユーザー |
![]() |
提出日時 | 2021-11-04 20:06:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 144 ms / 2,000 ms |
コード長 | 916 bytes |
コンパイル時間 | 5,485 ms |
コンパイル使用メモリ | 252,800 KB |
最終ジャッジ日時 | 2025-01-25 11:32:12 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 6 |
ソースコード
#include <stdio.h>#include <bits/stdc++.h>#include <atcoder/all>using namespace atcoder;using mint = modint1000000007;using namespace std;#define rep(i,n) for (int i = 0; i < (n); ++i)#define Inf 1000000000000000vector<int> get(vector<int> a){int n = a.size();vector<int> ret(n,0);vector dp(n,vector<long long>(n+1,Inf));rep(i,n){dp[i][1] = 0;rep(j,n+1){if(j==0)continue;rep(k,i){if(dp[k][j-1] < a[i] - a[k]){dp[i][j] = min(dp[i][j],(long long)a[i]-a[k]);}}}}rep(i,n){rep(j,n+1){if(dp[i][j]==Inf)continue;ret[i] = j;}}return ret;}int main(){int _t;cin>>_t;rep(_,_t){int N;cin>>N;vector<int> A(N);rep(i,N)cin>>A[i];auto a = get(A);reverse(A.begin(),A.end());auto b = get(A);reverse(b.begin(),b.end());int ans = 0;rep(i,N)ans = max(ans,a[i]+b[i]-1);cout<<ans<<endl;}return 0;}