結果
| 問題 | No.127 門松もどき |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-01-14 00:51:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 205 ms / 5,000 ms |
| コード長 | 1,083 bytes |
| 記録 | |
| コンパイル時間 | 1,409 ms |
| コンパイル使用メモリ | 159,668 KB |
| 実行使用メモリ | 90,548 KB |
| 最終ジャッジ日時 | 2024-12-23 21:51:31 |
| 合計ジャッジ時間 | 4,563 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define ITER(c) __typeof__((c).begin())
#define FOREACH(it, c) for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define REP(i, n) for(int(i)=0;(i)<(n);++(i))
#define RREP(i, n) for(int(i)=(n)-1;(i)>=0;--(i))
const int MOD = (int)1e9+7;
int N,M,W,H;
int A[3333];
int dp[2][3333][3333];
int dfs(int i, int j, int k){
if(j == k) return 1;
if(dp[i][j][k] >= 0) return dp[i][j][k];
int res = 0;
if(i == 0){
res = dfs(0,j,k-1);
if(A[j] < A[k]){
res = max(res, dfs(1,j+1,k)+1);
}
} else {
res = dfs(1,j+1,k);
if(A[j] > A[k]){
res = max(res, dfs(0,j,k-1)+1);
}
}
return dp[i][j][k] = res;
}
int main(){
cin >> N;
REP(i,N){
cin >> A[i];
}
memset(dp, -1, sizeof(dp));
int res = 0;
REP(i,N){
res = max(res, dfs(0,i,N-1));
res = max(res, dfs(1,0,i));
}
cout << res << endl;
}