結果

問題 No.127 門松もどき
ユーザー なおなお
提出日時 2015-01-14 00:51:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 198 ms / 5,000 ms
コード長 1,083 bytes
コンパイル時間 1,164 ms
コンパイル使用メモリ 144,244 KB
実行使用メモリ 90,468 KB
最終ジャッジ日時 2023-08-25 13:41:33
合計ジャッジ時間 4,527 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
90,132 KB
testcase_01 AC 25 ms
90,196 KB
testcase_02 AC 24 ms
90,140 KB
testcase_03 AC 24 ms
90,132 KB
testcase_04 AC 198 ms
90,324 KB
testcase_05 AC 24 ms
90,136 KB
testcase_06 AC 35 ms
90,252 KB
testcase_07 AC 25 ms
90,252 KB
testcase_08 AC 26 ms
90,144 KB
testcase_09 AC 25 ms
90,388 KB
testcase_10 AC 25 ms
90,252 KB
testcase_11 AC 25 ms
90,144 KB
testcase_12 AC 101 ms
90,324 KB
testcase_13 AC 114 ms
90,356 KB
testcase_14 AC 119 ms
90,284 KB
testcase_15 AC 156 ms
90,320 KB
testcase_16 AC 103 ms
90,296 KB
testcase_17 AC 113 ms
90,360 KB
testcase_18 AC 96 ms
90,468 KB
testcase_19 AC 66 ms
90,304 KB
testcase_20 AC 70 ms
90,256 KB
testcase_21 AC 44 ms
90,300 KB
testcase_22 AC 197 ms
90,328 KB
testcase_23 AC 167 ms
90,460 KB
testcase_24 AC 145 ms
90,352 KB
testcase_25 AC 173 ms
90,380 KB
testcase_26 AC 90 ms
90,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;

}
0