結果

問題 No.209 Longest Mountain Subsequence
ユーザー nanophoto12nanophoto12
提出日時 2016-01-07 00:02:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,962 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 85,604 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 16:19:53
合計ジャッジ時間 1,552 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
4,348 KB
testcase_01 AC 23 ms
4,348 KB
testcase_02 AC 22 ms
4,348 KB
testcase_03 AC 74 ms
4,348 KB
testcase_04 AC 73 ms
4,348 KB
testcase_05 AC 7 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <limits>

using namespace std;

#define FOR(x,y) for(int x = 0;x < (y);x++)
#define LLI long long int
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())

#define _L(x) cout<<(x)<<endl

int T,N,A[1010];
int L[101][101];
int R[101][101];

int Left(int left, int right)
{
    int& target = L[left][right];
    if(target >= 0)
    {
        return target;
    }
    target = 0;
    FOR(x, left)
    {
        if(A[x] < A[left] && A[left] - A[x] < A[right]-A[left])
        {
            target = max(target,Left(x, left) + 1);
        }
    }
    return target;
}

int Right(int left, int right)
{
    int& target = L[left][right];
    if(target >= 0)
    {
        return target;
    }
    target = 0;
    for(int x = right + 1;x < N;x++)
    {
        if(A[x] < A[right] && A[right] - A[x] < A[left]-A[right])
        {
            target = max(target,Right(right, x) + 1);
        }
    }
    return target;
}


int Calculate(int peakIndex)
{
    int left = 0;
    int right = 0;
    FOR(x, peakIndex)
    {
        if(A[x] < A[peakIndex])
        {
            left = max(left, Left(x,peakIndex) + 1);
        }
    }
    for(int x = peakIndex + 1;x < N;x++)
    {
        if(A[x] < A[peakIndex])
        {
            right = max(right, Right(peakIndex, x) + 1);
        }
    }
    return left + right + 1;
}

int main()
{
    int count = 0;
    cin >> count;
    FOR(m, count)
    {
        cin>>N;
        FOR(i,N) cin>>A[i];
        FOR(i,101) FOR(j,101)
        {
            L[i][j] = -1;
            R[i][j] = -1;
        }
        
        int maxLength = -1;
        FOR(i, N)
        {
            maxLength = max(maxLength, Calculate(i));
        }
        cout << maxLength << endl;
    }
    return 0;
}
0