結果

問題 No.1035 Color Box
ユーザー w0mbatw0mbat
提出日時 2020-04-24 22:45:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,771 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 82,828 KB
実行使用メモリ 62,340 KB
最終ジャッジ日時 2024-04-23 03:44:08
合計ジャッジ時間 2,806 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
61,008 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 42 ms
58,984 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 39 ms
53,708 KB
testcase_17 AC 38 ms
53,724 KB
testcase_18 WA -
testcase_19 AC 48 ms
60,632 KB
testcase_20 AC 38 ms
53,624 KB
testcase_21 AC 38 ms
53,160 KB
testcase_22 AC 38 ms
53,356 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 38 ms
52,832 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 40 ms
53,700 KB
testcase_31 AC 38 ms
53,336 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int, input().split())

class FactorialUtils:
    def __init__(self, n, mod=10**9+7):
        self.__mod = mod
        self.fac = [1] * (n+1)
        self.ifac = [1] * (n+1)
        for i in range(2, n+1): self.fac[i] = self.fac[i-1] * i % mod
        self.ifac[n] = pow(self.fac[n], mod-2, mod)
        for i in range(n, 1, -1): self.ifac[i-1] = self.ifac[i] * i % mod

    def choose(self, n, r):
        if r < 0 or r > n: return 0
        return (self.fac[n] * self.ifac[n-r] % self.__mod) * self.ifac[r] % self.__mod

    def multichoose(self, u, k):
        return (self.fac[u+k-1] * self.ifac[u-1] % self.__mod) * self.ifac[k] %self.__mod

MOD = 10**9+7
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

fu=FactorialUtils(N+1)
ans=Mint(fu.choose(N,M))
ans*=fu.fac[M]
ans*=fu.ifac[N-M+1]
ans*=pow(M,N-M,MOD)
print(ans)
0