結果

問題 No.127 門松もどき
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-18 17:21:33
言語 C++14
(gcc 12.2.0 + boost 1.81.0)
結果
AC  
実行時間 184 ms / 5,000 ms
コード長 1,010 bytes
コンパイル時間 1,871 ms
コンパイル使用メモリ 163,828 KB
実行使用メモリ 74,368 KB
最終ジャッジ日時 2023-07-25 03:13:35
合計ジャッジ時間 4,566 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 180 ms
74,224 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 16 ms
22,720 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
5,908 KB
testcase_12 AC 80 ms
54,616 KB
testcase_13 AC 93 ms
62,932 KB
testcase_14 AC 104 ms
60,768 KB
testcase_15 AC 143 ms
71,364 KB
testcase_16 AC 82 ms
60,760 KB
testcase_17 AC 90 ms
65,044 KB
testcase_18 AC 75 ms
58,656 KB
testcase_19 AC 47 ms
46,104 KB
testcase_20 AC 51 ms
48,108 KB
testcase_21 AC 25 ms
33,332 KB
testcase_22 AC 184 ms
74,368 KB
testcase_23 AC 151 ms
74,064 KB
testcase_24 AC 132 ms
66,964 KB
testcase_25 AC 157 ms
71,120 KB
testcase_26 AC 75 ms
50,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


int N, A[3010];
int memo[3010][3010][2];

int len(int l, int r, int sign) {
    if (memo[l][r][sign] != -1)
        return memo[l][r][sign];
    if (l == r)
        return 1;
    int tmp;
    if (sign) {
        if (A[l] > A[r]) {
            tmp = max(len(l, r - 1, !sign) + 1, len(l + 1, r, sign));
        } else
            tmp = len(l + 1, r, sign);
    } else {
        if (A[l] < A[r]) {
            tmp = max(len(l + 1, r, !sign) + 1, len(l, r - 1, sign));
        } else
            tmp = len(l, r - 1, sign);
    }
    return memo[l][r][sign] = tmp;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            for (int k = 0; k < 2; k++)
                memo[i][j][k] = -1;

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, len(i, N - 1, 0));
        ans = max(ans, len(0, i, 1));
    }

    cout << ans << endl;
}
0