結果

問題 No.127 門松もどき
ユーザー mayoko_mayoko_
提出日時 2015-01-14 08:54:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 104 ms / 5,000 ms
コード長 1,162 bytes
コンパイル時間 483 ms
コンパイル使用メモリ 73,096 KB
実行使用メモリ 74,304 KB
最終ジャッジ日時 2023-08-25 13:41:49
合計ジャッジ時間 2,988 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
74,304 KB
testcase_01 AC 27 ms
74,256 KB
testcase_02 AC 27 ms
74,124 KB
testcase_03 AC 26 ms
74,104 KB
testcase_04 AC 97 ms
74,184 KB
testcase_05 AC 27 ms
74,112 KB
testcase_06 AC 30 ms
74,176 KB
testcase_07 AC 27 ms
74,188 KB
testcase_08 AC 27 ms
74,128 KB
testcase_09 AC 27 ms
74,192 KB
testcase_10 AC 28 ms
74,184 KB
testcase_11 AC 28 ms
74,120 KB
testcase_12 AC 65 ms
74,208 KB
testcase_13 AC 77 ms
74,124 KB
testcase_14 AC 70 ms
74,116 KB
testcase_15 AC 92 ms
74,136 KB
testcase_16 AC 71 ms
74,208 KB
testcase_17 AC 79 ms
74,136 KB
testcase_18 AC 67 ms
74,184 KB
testcase_19 AC 51 ms
74,124 KB
testcase_20 AC 51 ms
74,284 KB
testcase_21 AC 35 ms
74,172 KB
testcase_22 AC 99 ms
74,184 KB
testcase_23 AC 104 ms
74,132 KB
testcase_24 AC 81 ms
74,140 KB
testcase_25 AC 91 ms
74,112 KB
testcase_26 AC 57 ms
74,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define INF 1000000000

using namespace std;
typedef long long ll;

const int MAXN = 3010;
int A[MAXN];
int dpL[MAXN][MAXN];
int dpR[MAXN][MAXN];

int main(void) {
    int N;
    int ret = 1;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < MAXN; i++) for (int j = 0; j < MAXN; j++) {
        dpL[i][j] = dpR[i][j] = 1;
    }
    for (int w = 1; w < N; w++) {
        for (int x = 0; x+w < N; x++) {
            dpL[x][x+w] = max(dpL[x][x+w], dpL[x][x+w-1]);
            dpR[x][x+w] = max(dpR[x][x+w], dpR[x+1][x+w]);
            if (A[x] < A[x+w]) {
                dpL[x][x+w] = max(dpL[x][x+w], 1 + dpR[x+1][x+w]);
            }
            if (A[x] > A[x+w]) {
                dpR[x][x+w] = max(dpR[x][x+w], dpL[x][x+w-1]+1);
            }
            ret = max(ret, max(dpL[x][x+w], dpR[x][x+w]));
        }
    }
    cout << ret << endl;
    return 0;
}
0