結果

問題 No.209 Longest Mountain Subsequence
ユーザー mamekinmamekin
提出日時 2015-07-22 23:27:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,573 bytes
コンパイル時間 2,594 ms
コンパイル使用メモリ 93,184 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 21:28:31
合計ジャッジ時間 1,898 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int t;
    cin >> t;

    while(--t >= 0){
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i=0; i<n; ++i)
            cin >> a[i];

        vector<vector<int> > dp(n, vector<int>(n, 0));
        for(int i=0; i<n; ++i)
            dp[i][i] = 1;

        for(int i=0; i<n; ++i){
            for(int j=i; j<n; ++j){
                if(a[i] <= a[j]){
                    for(int k=j+1; k<n; ++k){
                        if(a[j] - a[i] < a[k] - a[j])
                            dp[j][k] = max(dp[j][k], dp[i][j] + 1);
                        else if(a[k] < a[j])
                            dp[j][k] = max(dp[j][k], dp[i][j] + 1);
                    }
                }
                else{
                    for(int k=j+1; k<n; ++k){
                        if(a[j] > a[k] && a[i] - a[j] > a[j] - a[k])
                            dp[j][k] = max(dp[j][k], dp[i][j] + 1);
                    }
                }
            }
        }

        int ans = 0;
        for(int i=0; i<n; ++i){
            for(int j=i; j<n; ++j){
                ans = max(ans, dp[i][j]);
            }
        }
        cout << ans << endl;
    }

    return 0;
}
0