結果

問題 No.790 ちきんの括弧並べ
ユーザー 👑 emthrmemthrm
提出日時 2019-09-22 17:55:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,005 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 73,676 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 07:20:40
合計ジャッジ時間 1,387 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)

const int MOD = 1000000007; // 998244353;
/*-------------------------------------------------*/
vector<long long> inv_init(int val, long long mod = MOD) {
  vector<long long> inv(val + 1, 0);
  if (val >= 1) {
    inv[1] = 1;
    FOR(i, 2, val + 1) {
      inv[i] = mod - inv[mod % i] * (mod / i) % mod;
      if (inv[i] == mod) inv[i] = 0;
    }
  }
  return inv;
}

vector<long long> catalan_number(int val, long long mod = MOD) {
  vector<long long> res(val + 1), inv = inv_init(val + 1, mod);
  res[0] = 1;
  REP(i, val) res[i + 1] = res[i] * inv[i + 2] % mod * 2 % mod * (2 * i + 1) % mod;
  return res;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  vector<long long> catalan = catalan_number(13, 742909);
  int n; cin >> n;
  cout << catalan[n] << '\n';
  return 0;
}
0