結果

問題 No.127 門松もどき
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-18 14:43:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 890 bytes
コンパイル時間 1,397 ms
コンパイル使用メモリ 164,100 KB
実行使用メモリ 74,100 KB
最終ジャッジ日時 2024-04-09 21:28:42
合計ジャッジ時間 12,315 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,944 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,944 KB
testcase_08 WA -
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 4 ms
8,000 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = 1;
    if (sign) {
        for (int x = l; x <= r - 1; x++) {
            if (A[x] > A[r])
                tmp = max(tmp, len(x, r - 1, !sign) + 1);
        }
    } else {
        for (int x = l + 1; x <= r; x++) {
            if (A[x] > A[l])
                tmp = max(tmp, len(l + 1, x, !sign) + 1);
        }
    }
    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