結果

問題 No.1035 Color Box
ユーザー NatsubiSoganNatsubiSogan
提出日時 2020-10-01 17:49:33
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 667 ms / 2,000 ms
コード長 796 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 18,560 KB
最終ジャッジ日時 2024-07-07 01:28:35
合計ジャッジ時間 6,565 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7
class counting:
    def __init__(self, n):
        self.n = n
        self.fa = [1] * (self.n + 1)
        self.fi = [1] * (self.n + 1)
        for i in range(1, self.n + 1):
            self.fa[i] = self.fa[i - 1] * i % mod
            self.fi[i] = pow(self.fa[i], mod - 2, mod)
    def comb(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod
    def per(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[n - r] % mod
n, m = map(int, input().split())
C = counting(m + 1)
ans = 0
for i in range(m + 1):
    cur = C.comb(m, i) * pow(i, n, mod) % mod
    if (m - i) % 2:
        cur *= -1
    ans += cur
    ans %= mod
print(ans)
0