結果
| 問題 |
No.209 Longest Mountain Subsequence
|
| コンテスト | |
| ユーザー |
y_mazun
|
| 提出日時 | 2015-05-15 22:51:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 185 ms / 2,000 ms |
| コード長 | 1,010 bytes |
| コンパイル時間 | 355 ms |
| コンパイル使用メモリ | 50,760 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-06 04:12:08 |
| 合計ジャッジ時間 | 1,382 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 |
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:6:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
6 | inline int getInt(){ int s; scanf("%d", &s); return s; }
| ~~~~~^~~~~~~~~~
ソースコード
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }
#include <set>
using namespace std;
vector<int> solve(const vector<int> &a){
const int n = a.size();
vector<int> ret(n);
const int inf = 1000000000 + 10;
vector<vector<int> > dp(n + 1, vector<int>(n + 1, inf));
REP(i,n){
REP(j,n+1) REP(k,n+1) if(dp[j][k] != inf){
if(dp[j][k] < a[i] - a[j])
dp[i][k + 1] = min(dp[i][k + 1], a[i] - a[j]);
}
dp[i][1] = 0;
REP(j,n+1) if(dp[i][j] != inf)
ret[i] = j;
}
return ret;
}
int main(){
const int t = getInt();
REP(_,t){
const int n = getInt();
vector<int> a(n);
REP(i,n) a[i] = getInt();
vector<int> dp1 = solve(a);
reverse(a.begin(), a.end());
vector<int> dp2 = solve(a);
reverse(dp2.begin(), dp2.end());
int ans = 0;
REP(i,n) ans = max(ans, dp1[i] + dp2[i] - 1);
printf("%d\n", ans);
}
return 0;
}
y_mazun