結果

問題 No.127 門松もどき
ユーザー simansiman
提出日時 2023-01-08 21:24:16
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,324 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 106,136 KB
実行使用メモリ 73,884 KB
最終ジャッジ日時 2023-08-22 06:13:37
合計ジャッジ時間 3,470 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 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 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 32 ms
40,520 KB
testcase_13 AC 40 ms
53,176 KB
testcase_14 AC 38 ms
48,828 KB
testcase_15 AC 51 ms
66,560 KB
testcase_16 AC 35 ms
47,292 KB
testcase_17 AC 33 ms
54,500 KB
testcase_18 AC 29 ms
45,620 KB
testcase_19 AC 19 ms
29,108 KB
testcase_20 AC 18 ms
29,908 KB
testcase_21 AC 11 ms
15,576 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;
const int MAX_N = 3010;
int A[MAX_N];

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

  int dpL[N + 1][N];
  int dpR[N + 1][N];
  memset(dpL, 0, sizeof(dpL));
  memset(dpR, 0, sizeof(dpR));

  for (int i = 0; i < N; ++i) {
    for (int l = 0; l < N - i; ++l) {
      int r = l + i;

      if (i == 0) {
        dpL[i + 1][r] = 1;
        dpR[i + 1][l] = 1;
      } else {
        dpR[i + 1][l] = max(dpR[i + 1][l], dpR[i][l]);
        dpL[i + 1][r] = max(dpL[i + 1][r], dpL[i][r]);

        if (A[l] < A[r]) {
          dpR[i + 1][l] = max(dpR[i + 1][l], dpL[i][r] + 1);
        }
        if (A[l] > A[r]) {
          dpL[i + 1][r] = max(dpL[i + 1][r], dpR[i][l] + 1);
        }
      }
    }

    /*
    for (int j = 0; j < N; ++j) {
      cerr << dpL[i + 1][j] << " ";
    }
    cerr << endl;

    for (int j = 0; j < N; ++j) {
      cerr << dpR[i + 1][j] << " ";
    }
    cerr << endl;
    */
  }

  int ans = 0;

  for (int i = 0; i < N; ++i) {
    ans = max(ans, max(dpL[N][i], dpR[N][i]));
  }

  cout << ans << endl;

  return 0;
}
0