結果

問題 No.1960 Guruguru Permutation
ユーザー tktk_snsntktk_snsn
提出日時 2022-05-28 00:07:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,509 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 11,916 KB
実行使用メモリ 25,928 KB
最終ジャッジ日時 2023-10-20 21:35:22
合計ジャッジ時間 5,024 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
25,928 KB
testcase_01 AC 116 ms
25,928 KB
testcase_02 AC 115 ms
25,928 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 183 ms
25,928 KB
testcase_08 AC 159 ms
25,928 KB
testcase_09 AC 159 ms
25,928 KB
testcase_10 AC 143 ms
25,928 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 193 ms
25,928 KB
testcase_14 AC 120 ms
25,928 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 166 ms
25,928 KB
testcase_19 AC 114 ms
25,928 KB
testcase_20 AC 177 ms
25,928 KB
testcase_21 AC 115 ms
25,928 KB
testcase_22 AC 230 ms
25,928 KB
testcase_23 AC 173 ms
25,928 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
mod = 998244353
U = 2 * 10 ** 5 + 10


class Combination:
    """
    SIZEが10**6程度以下の二項係数を何回も呼び出したいときに使う
    使い方:
    comb = Combination(SIZE, MOD)
    comb(10, 3) => 120
    """

    def __init__(self, N, MOD=10 ** 9 + 7):
        self.MOD = MOD
        self.__make_factorial_list(N)

    def __call__(self, n, k):
        if k < 0 or k > n:
            return 0
        res = self.fact[n] * self.inv[k] % self.MOD
        res = res * self.inv[n - k] % self.MOD
        return res

    def nPk(self, n, k):
        if k < 0 or k > n:
            return 0
        return self.fact[n] * self.inv[n - k] % self.MOD

    def nHk(self, n, k):
        if k == 0:
            return 1
        return self.__call__(n + k - 1, k)

    def __make_factorial_list(self, N):
        self.fact = [1] * (N + 1)
        self.inv = [1] * (N + 1)
        MOD = self.MOD
        for i in range(1, N + 1):
            self.fact[i] = (self.fact[i - 1] * i) % MOD
        self.inv[N] = pow(self.fact[N], MOD - 2, MOD)
        for i in range(N, 0, -1):
            self.inv[i - 1] = (self.inv[i] * i) % MOD
        return


comb = Combination(U, mod)
fact = comb.fact
inv = comb.inv
N, L, R = map(int, input().split())

M = max(0, L + R - N)
L -= M
R -= M

ans = 0
for i in range(min(L, R) + 1):
    pair = comb(L, i) * comb.nPk(R, i) % mod
    ans = (ans + pair) % mod

for i in range(N - L - R):
    ans = ans * (N - i) % mod

print(ans)
0