結果

問題 No.391 CODING WAR
ユーザー rpy3cpprpy3cpp
提出日時 2016-07-11 12:57:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,136 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 10,996 KB
実行使用メモリ 8,352 KB
最終ジャッジ日時 2023-08-03 14:02:57
合計ジャッジ時間 1,431 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 15 ms
8,300 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 16 ms
8,192 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

class nCb(object):
    def __init__(self, max_n, mod = 10**9 + 7):
        self.max_n = max_n
        self.mod = mod
        self.fac = self._init_factorials()
        self.inv = self._init_inv()
        
    def _init_factorials(self):
        N = self.max_n
        mod = self.mod
        f = 1
        fac = [1] * (N + 1)
        for i in range(1, N + 1):
            f *= i
            f %= mod
            fac[i] = f
        return fac

    def _init_inv(self):
        N = self.max_n
        mod = self.mod
        ret = pow(self.fac[N], mod - 2, mod)
        inv = [1] * (N + 1)
        inv[N] = ret
        for i in range(N-1, 0, -1):
            ret *= i + 1
            ret %= mod
            inv[i] = ret
        return inv

    def get(self, n, b):
        return (self.fac[n] * self.inv[b] * self.inv[n-b]) % self.mod


def solve(N, M):
    if N < M:
        return 0
    mod = 10**9 + 7
    ncb = nCb(M, M, mod)
    ans = 0
    sig = 1
    for i in range(M, 0, -1):
        ans += sig * ncb.get(M, i) * pow(i, N, mod)
        ans %= mod
        sig *= -1
    return ans

N, M = map(int, input().split())
print(solve(N, M))
0