結果
問題 | No.209 Longest Mountain Subsequence |
ユーザー |
![]() |
提出日時 | 2016-01-07 00:02:10 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 67 ms / 2,000 ms |
コード長 | 1,962 bytes |
コンパイル時間 | 585 ms |
コンパイル使用メモリ | 84,640 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-19 12:25:52 |
合計ジャッジ時間 | 1,261 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 6 |
ソースコード
#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)<<endlint 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;}