結果

問題 No.391 CODING WAR
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-15 12:11:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 554 ms / 2,000 ms
コード長 1,191 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 11,976 KB
実行使用メモリ 17,972 KB
最終ジャッジ日時 2023-10-20 05:56:12
合計ジャッジ時間 5,646 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,152 KB
testcase_01 AC 29 ms
10,152 KB
testcase_02 AC 29 ms
10,152 KB
testcase_03 AC 29 ms
10,152 KB
testcase_04 AC 28 ms
10,152 KB
testcase_05 AC 28 ms
10,168 KB
testcase_06 AC 29 ms
10,152 KB
testcase_07 AC 29 ms
10,168 KB
testcase_08 AC 29 ms
10,160 KB
testcase_09 AC 554 ms
17,972 KB
testcase_10 AC 453 ms
17,972 KB
testcase_11 AC 366 ms
17,972 KB
testcase_12 AC 28 ms
10,152 KB
testcase_13 AC 507 ms
17,948 KB
testcase_14 AC 430 ms
16,000 KB
testcase_15 AC 502 ms
16,848 KB
testcase_16 AC 303 ms
13,964 KB
testcase_17 AC 345 ms
14,872 KB
testcase_18 AC 250 ms
13,172 KB
testcase_19 AC 254 ms
13,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 __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


mod = 10 ** 9 + 7
N, M = map(int, input().split())
comb = Combination(M + 10, mod)

ans = 0
for k in range(M + 1):  #M個中k個の問題を解かないの確定、他は任意
    cnt = comb(M, k) * pow(M - k, N, mod) % mod
    if k & 1:
        cnt = mod - cnt
    ans += cnt
    ans %= mod
   
   
print(ans)

0