結果

問題 No.790 ちきんの括弧並べ
ユーザー htkbhtkb
提出日時 2019-02-20 23:45:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 970 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 10,836 KB
実行使用メモリ 7,960 KB
最終ジャッジ日時 2023-08-07 19:15:15
合計ジャッジ時間 1,248 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,872 KB
testcase_01 AC 15 ms
7,816 KB
testcase_02 AC 15 ms
7,812 KB
testcase_03 AC 16 ms
7,812 KB
testcase_04 AC 16 ms
7,820 KB
testcase_05 AC 16 ms
7,920 KB
testcase_06 AC 15 ms
7,852 KB
testcase_07 AC 15 ms
7,908 KB
testcase_08 AC 15 ms
7,808 KB
testcase_09 AC 15 ms
7,808 KB
testcase_10 AC 15 ms
7,916 KB
testcase_11 AC 15 ms
7,916 KB
testcase_12 AC 16 ms
7,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BigCombination(object):
    __slots__ = ["mod", "factorial", "inverse"]

    def __init__(self, mod: int = 10**9+7, max_n: int = 10**6):
        fac, inv = [1], []
        fac_append, inv_append = fac.append, inv.append

        for i in range(1, max_n+1):
            fac_append(fac[-1] * i % mod)

        inv_append(pow(fac[-1], mod-2, mod))

        for i in range(max_n, 0, -1):
            inv_append(inv[-1] * i % mod)

        self.mod, self.factorial, self.inverse = mod, fac, inv[::-1]

    def get_combination(self, n, r):
        return self.factorial[n] * self.inverse[r] * self.inverse[n-r] % self.mod

    def get_permutation(self, n, r):
        return self.factorial[n] * self.inverse[n-r] % self.mod

    def get_catalan_number(self, n):
        return self.factorial[2*n] * self.inverse[n+1] * self.inverse[n] % self.mod


if __name__ == "__main__":
    n = int(input())
    comb = BigCombination(max_n=2*n)
    print(comb.get_catalan_number(n))
0