結果

問題 No.127 門松もどき
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-18 17:21:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 169 ms / 5,000 ms
コード長 1,010 bytes
コンパイル時間 1,347 ms
コンパイル使用メモリ 164,036 KB
実行使用メモリ 74,380 KB
最終ジャッジ日時 2024-04-09 21:30:44
合計ジャッジ時間 3,674 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 168 ms
74,280 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 15 ms
22,992 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 75 ms
55,860 KB
testcase_13 AC 89 ms
64,424 KB
testcase_14 AC 93 ms
61,748 KB
testcase_15 AC 133 ms
71,588 KB
testcase_16 AC 78 ms
60,448 KB
testcase_17 AC 94 ms
64,300 KB
testcase_18 AC 72 ms
59,380 KB
testcase_19 AC 44 ms
47,660 KB
testcase_20 AC 46 ms
48,052 KB
testcase_21 AC 23 ms
33,388 KB
testcase_22 AC 169 ms
74,380 KB
testcase_23 AC 142 ms
74,340 KB
testcase_24 AC 123 ms
66,420 KB
testcase_25 AC 146 ms
71,112 KB
testcase_26 AC 60 ms
51,224 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