結果

問題 No.127 門松もどき
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-18 17:11:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 908 bytes
コンパイル時間 2,414 ms
コンパイル使用メモリ 164,448 KB
実行使用メモリ 74,200 KB
最終ジャッジ日時 2023-07-25 03:13:29
合計ジャッジ時間 4,700 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,384 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 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
6,052 KB
testcase_12 AC 58 ms
54,500 KB
testcase_13 AC 76 ms
63,088 KB
testcase_14 AC 72 ms
60,760 KB
testcase_15 AC 96 ms
71,244 KB
testcase_16 AC 68 ms
60,880 KB
testcase_17 AC 71 ms
64,980 KB
testcase_18 AC 61 ms
58,864 KB
testcase_19 AC 40 ms
46,004 KB
testcase_20 AC 40 ms
48,120 KB
testcase_21 AC 21 ms
33,572 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

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;

    cout << max(len(0, N - 1, 0), len(0, N - 1, 1)) << endl;
}
0