結果

問題 No.336 門松列列
ユーザー Fu_LFu_L
提出日時 2023-10-20 21:55:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,509 bytes
コンパイル時間 4,531 ms
コンパイル使用メモリ 264,948 KB
実行使用メモリ 10,924 KB
最終ジャッジ日時 2023-10-20 21:55:46
合計ジャッジ時間 5,205 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<ll, ll>;
using mint = modint1000000007;
#define rep(i, a, b) for(ll i = a; i < b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)
constexpr ll inf = 4e18;
struct Binomial {
    vector<mint> fac, ifac;
    Binomial(int n)
        : fac(n + 1), ifac(n + 1) {
        fac[0] = 1;
        rep(i, 1, n + 1) fac[i] = fac[i - 1] * i;
        ifac[n] = fac[n].inv();
        rrep(i, n, 1) ifac[i - 1] = ifac[i] * i;
    }
    mint fact(int n) {
        if(n < 0) return 0;
        return fac[n];
    }
    mint perm(int n, int r) {
        if(n < 0 or n < r or r < 0) return 0;
        return fac[n] * ifac[n - r];
    }
    mint comb(int n, int r) {
        if(n < 0 or n < r or r < 0) return 0;
        return fac[n] * ifac[n - r] * ifac[r];
    }
    mint homo(int n, int r) {
        if(n < 0 or r < 0) return 0;
        if(r == 0) return 1;
        return comb(n + r - 1, r);
    }
    mint operator()(int n, int r) {
        return comb(n, r);
    }
} binom(1000005);
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    if(n <= 2) {
        cout << 0 << '\n';
        return 0;
    }
    vector<mint> dp(n + 1);
    dp[0] = 2;
    dp[1] = 2;
    dp[2] = 2;
    rep(i, 3, n + 1) {
        rep(j, 0, i) {
            dp[i] += binom(i - 1, j) * dp[j] * dp[i - 1 - j];
        }
        dp[i] /= 4;
    }
    cout << dp[n].val() << '\n';
}
0