結果
| 問題 |
No.209 Longest Mountain Subsequence
|
| コンテスト | |
| ユーザー |
tea_pt
|
| 提出日時 | 2015-05-22 15:03:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,700 bytes |
| コンパイル時間 | 655 ms |
| コンパイル使用メモリ | 89,044 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-06 04:43:03 |
| 合計ジャッジ時間 | 1,083 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 5 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <stack>
#include <array>
#include <fstream>
#define REP(i,n) for(int (i) = 0;(i) < (n) ; ++(i))
#define REPA(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i))
#if defined(_MSC_VER)||__cplusplus > 199711L
#define AUTO(r,v) auto r = (v)
#else
#define AUTO(r,v) typeof(v) r = (v)
#endif
#define ALL(c) (c).begin() , (c).end()
#define EACH(it,c) for(AUTO(it,(c).begin());it != (c).end();++it)
#define LL long long
#define int LL
#define INF 99999999
#define DEV 1000000007
#define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
int N;
int Left[110][110];
int Right[110][110];
signed main()
{
QUICK_CIN;
//ifstream cin("debug.txt");
//ofstream cout("result.txt");
cin >> N;
REP(j, N){
int T;
cin >> T;
vector<int> arr(T);
vector<int> max_left(T,1);
vector<int> max_right(T,1);
fill(&Left[0][0], &Left[0][0] + 110 * 110, INF);
fill(&Right[0][0], &Right[0][0] + 110 * 110, INF);
REP(i, T){
cin >> arr[i];
}
Left[0][0] = arr[0];
REP(m, T - 1){
Left[0][m + 1] = min(Left[0][m], arr[m + 1]);
}
int Llen;
REPA(1,m, T-1){
bool update = false;
REPA(m, n, T){
if (Left[m-1][n] < arr[n] ){
if (m<2||(m > 1 && Left[m - 1][n] - Left[m - 2][n] < arr[n] - Left[m - 1][n])){
Left[m][n] = min(arr[n], Left[m][n - 1]);
update = true;
}
else{
Left[m][n] = Left[m][n - 1];
}
}
else{
Left[m][n] = Left[m][n - 1];
}
if (Left[m][n] != INF){
max_left[n] = max(m+1,max_left[n]);
}
}
if (!update){
Llen = m;
break;
}
}
std::reverse(ALL(arr));
Right[0][0] = arr[0];
REP(m, T - 1){
Right[0][m + 1] = min(Right[0][m], arr[m + 1]);
}
int Rlen;
REPA(1, m, T - 1){
bool update = false;
REPA(m, n, T){
if (Right[m - 1][n] < arr[n]){
if (m<2 || (m > 1 && Left[m - 1][n] - Right[m - 2][n] < arr[n] - Left[m - 1][n])){
Right[m][n] = min(arr[n], Right[m][n - 1]);
update = true;
}
else{
Right[m][n] = Right[m][n - 1];
}
}
else{
Right[m][n] = Right[m][n - 1];
}
if (Right[m][n] != INF){
max_right[n] = max(m + 1, max_right[n]);
}
}
if (!update){
Rlen = m;
break;
}
}
int ma = 0;
REP(i, T){
ma = max(ma, max_left[i] + max_right[T-1-i]-1);
}
cout << ma << endl;
}
return 0;
}
tea_pt