結果

問題 No.209 Longest Mountain Subsequence
ユーザー koyumeishi
提出日時 2015-05-15 23:41:47
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,329 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 79,888 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-06 04:23:13
合計ジャッジ時間 1,046 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
void solve(){
int n;
cin >> n;
vector<int> a(n);
for(int i=0; i<n; i++){
cin >> a[i];
}
auto func = [&](){
const int INF = 1000000007;
vector<vector<int>> dp(n+1, vector<int>(n+2, INF));
for(int i=0; i<n; i++){
dp[i][1] = 0;
}
for(int i=1; i<n; i++){
for(int last=0; last<i; last++){
int diff = a[i] - a[last];
if(diff <= 0) continue;
for(int len=1; len<=last+1; len++){
if(dp[last][len] < diff){
//cerr << i << " " << last << " " << len <<" " << dp[last][len] << " " << diff << endl;
dp[i][len+1] = min(dp[i][len+1], diff);
}
}
}
}
vector<int> ret(n, 0);
for(int i=0; i<n; i++){
for(int j=0; j<n+1; j++){
if(dp[i][j] != INF) ret[i] = j;
//cerr << dp[i][j] << " ";
}
//cerr << endl;
}
return ret;
};
vector<int> g = func();
reverse(a.begin(), a.end());
vector<int> l = func();
reverse(l.begin(), l.end());
int ans = 1;
for(int i=0; i<n; i++){
ans = max(ans, g[i] + l[i] - 1);
//cerr << g[i] << " " << l[i] << endl;
}
cout << ans << endl;
}
int main(){
int t;
cin >> t;
while(t--){
solve();
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0