結果

問題 No.127 門松もどき
コンテスト
ユーザー siman
提出日時 2023-01-08 21:24:16
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,324 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,108 ms
コンパイル使用メモリ 150,016 KB
実行使用メモリ 74,140 KB
最終ジャッジ日時 2026-05-26 07:19:37
合計ジャッジ時間 6,815 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15 WA * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:25:18: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   25 |   int dpL[N + 1][N];
      |                  ^
main.cpp:25:18: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
   19 |   int N;
      |       ^
main.cpp:25:11: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   25 |   int dpL[N + 1][N];
      |           ^~~~~
main.cpp:25:11: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
   19 |   int N;
      |       ^
main.cpp:26:18: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   26 |   int dpR[N + 1][N];
      |                  ^
main.cpp:26:18: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
   19 |   int N;
      |       ^
main.cpp:26:11: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   26 |   int dpR[N + 1][N];
      |           ^~~~~
main.cpp:26:11: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
   19 |   int N;
      |       ^
4 warnings generated.

ソースコード

diff #
raw source code

#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