結果

問題 No.790 ちきんの括弧並べ
ユーザー Hoi_koroHoi_koro
提出日時 2019-02-20 22:05:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 166,772 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 08:22:17
合計ジャッジ時間 2,481 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

struct Problem {
  int n;
  vector<vector<LL>> dp;
  Problem(LL n) : n(n), dp(2 * n + 1, vector<LL>(2 * n + 1)){};

  void solve() {
    dp[0][0] = 1;
    for (int i = 1; i <= 2 * n; ++i) {
      for (int j = 0; j <= i; ++j) {
        if (j * 2 < i) continue;
        dp[i][j] += dp[i - 1][j];
        if (j > 0) dp[i][j] += dp[i - 1][j - 1];
      }
    }
    cout << dp[2 * n][n] << endl;
  }
};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  long long n = 0;
  cin >> n;
  Problem p(n);
  p.solve();
  return 0;
}
0