結果

問題 No.209 Longest Mountain Subsequence
ユーザー y_mazuny_mazun
提出日時 2015-05-15 22:51:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 1,010 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 53,468 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 08:27:10
合計ジャッジ時間 1,743 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
4,380 KB
testcase_01 AC 64 ms
4,376 KB
testcase_02 AC 60 ms
4,380 KB
testcase_03 AC 215 ms
4,376 KB
testcase_04 AC 213 ms
4,380 KB
testcase_05 AC 54 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0