結果

問題 No.127 門松もどき
ユーザー simansiman
提出日時 2023-01-08 21:26:09
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,328 bytes
コンパイル時間 1,001 ms
コンパイル使用メモリ 106,460 KB
実行使用メモリ 74,392 KB
最終ジャッジ日時 2023-08-22 06:15:43
合計ジャッジ時間 2,914 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
74,204 KB
testcase_01 AC 21 ms
74,192 KB
testcase_02 AC 20 ms
74,308 KB
testcase_03 AC 21 ms
74,192 KB
testcase_04 WA -
testcase_05 AC 20 ms
74,356 KB
testcase_06 WA -
testcase_07 AC 20 ms
74,260 KB
testcase_08 WA -
testcase_09 AC 20 ms
74,344 KB
testcase_10 AC 20 ms
74,252 KB
testcase_11 AC 20 ms
74,252 KB
testcase_12 AC 37 ms
74,308 KB
testcase_13 AC 41 ms
74,260 KB
testcase_14 AC 39 ms
74,392 KB
testcase_15 AC 47 ms
74,348 KB
testcase_16 AC 38 ms
74,260 KB
testcase_17 AC 34 ms
74,288 KB
testcase_18 AC 33 ms
74,260 KB
testcase_19 AC 27 ms
74,376 KB
testcase_20 AC 27 ms
74,344 KB
testcase_21 AC 25 ms
74,308 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 dpL[MAX_N][MAX_N];
int dpR[MAX_N][MAX_N];

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

  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