結果

問題 No.127 門松もどき
ユーザー imgry22imgry22
提出日時 2015-01-21 18:33:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,494 bytes
コンパイル時間 1,269 ms
コンパイル使用メモリ 143,700 KB
実行使用メモリ 50,960 KB
最終ジャッジ日時 2023-09-05 02:43:06
合計ジャッジ時間 4,521 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 182 ms
43,672 KB
testcase_17 AC 181 ms
48,380 KB
testcase_18 AC 160 ms
42,592 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000007
#define EPS 1E-12

const int MAX_N = 3000;
int n;
int A[MAX_N];
int dp[2][MAX_N][MAX_N];

int lsolve(int L, int R);
int rsolve(int L, int R);

int lsolve(int L, int R)
{
  if(dp[0][L][R]) return dp[0][L][R];
  if(L == R) return dp[0][L][R] = 1;
  if(A[L] >= A[R]) return dp[0][L][R] = lsolve(L, R-1);
  return dp[0][L][R] = max(lsolve(L, R-1), rsolve(L+1, R)+1);
}

int rsolve(int L, int R)
{
  if(dp[1][L][R]) return dp[1][L][R];
  if(L == R) return dp[1][L][R] = 1;
  if(A[L] <= A[R]) return dp[1][L][R] = rsolve(L+1, R);
  return dp[1][L][R] = max(rsolve(L+1, R), lsolve(L, R-1)+1);
}

int main()
{
  cin >> n;
  rep(i, n) cin >> A[i];

  cout << lsolve(0, n-1) << endl;

  return 0;
}
0