結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
74,300 KB
testcase_01 AC 20 ms
74,384 KB
testcase_02 AC 21 ms
74,268 KB
testcase_03 WA -
testcase_04 AC 54 ms
74,268 KB
testcase_05 WA -
testcase_06 AC 24 ms
74,368 KB
testcase_07 AC 21 ms
74,264 KB
testcase_08 AC 21 ms
74,260 KB
testcase_09 AC 20 ms
74,196 KB
testcase_10 AC 20 ms
74,252 KB
testcase_11 AC 20 ms
74,284 KB
testcase_12 AC 37 ms
74,232 KB
testcase_13 AC 41 ms
74,228 KB
testcase_14 AC 41 ms
74,256 KB
testcase_15 AC 48 ms
74,304 KB
testcase_16 AC 38 ms
74,268 KB
testcase_17 AC 34 ms
74,224 KB
testcase_18 AC 34 ms
74,264 KB
testcase_19 AC 28 ms
74,304 KB
testcase_20 AC 27 ms
74,352 KB
testcase_21 AC 24 ms
74,256 KB
testcase_22 AC 52 ms
74,332 KB
testcase_23 AC 47 ms
74,296 KB
testcase_24 AC 45 ms
74,336 KB
testcase_25 AC 51 ms
74,244 KB
testcase_26 AC 37 ms
74,292 KB
権限があれば一括ダウンロードができます

ソースコード

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));
  int ans = 0;

  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);
          ans = max(ans, dpR[i + 1][l]);
        }
        if (A[l] > A[r]) {
          dpL[i + 1][r] = max(dpL[i + 1][r], dpR[i][l] + 1);
          ans = max(ans, dpL[i + 1][r]);
        }
      }
    }

    /*
    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;
    */
  }

  cout << ans << endl;

  return 0;
}
0