結果

問題 No.1035 Color Box
ユーザー w0mbatw0mbat
提出日時 2020-04-24 23:45:19
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 2,799 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 86,588 KB
実行使用メモリ 80,312 KB
最終ジャッジ日時 2023-08-05 06:13:57
合計ジャッジ時間 6,182 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
80,312 KB
testcase_01 AC 75 ms
75,692 KB
testcase_02 AC 70 ms
70,944 KB
testcase_03 AC 84 ms
76,348 KB
testcase_04 AC 91 ms
77,752 KB
testcase_05 AC 84 ms
76,660 KB
testcase_06 AC 73 ms
70,904 KB
testcase_07 AC 82 ms
77,120 KB
testcase_08 AC 122 ms
80,008 KB
testcase_09 AC 103 ms
78,720 KB
testcase_10 AC 76 ms
76,300 KB
testcase_11 AC 73 ms
75,432 KB
testcase_12 AC 76 ms
75,624 KB
testcase_13 AC 115 ms
79,596 KB
testcase_14 AC 121 ms
79,732 KB
testcase_15 AC 124 ms
80,192 KB
testcase_16 AC 69 ms
70,884 KB
testcase_17 AC 70 ms
71,000 KB
testcase_18 AC 68 ms
71,096 KB
testcase_19 AC 125 ms
80,288 KB
testcase_20 AC 72 ms
71,092 KB
testcase_21 AC 73 ms
70,980 KB
testcase_22 AC 73 ms
70,988 KB
testcase_23 AC 76 ms
71,296 KB
testcase_24 AC 73 ms
70,988 KB
testcase_25 AC 72 ms
70,944 KB
testcase_26 AC 75 ms
71,320 KB
testcase_27 AC 72 ms
71,272 KB
testcase_28 AC 71 ms
71,296 KB
testcase_29 AC 74 ms
70,876 KB
testcase_30 AC 71 ms
71,300 KB
testcase_31 AC 70 ms
71,200 KB
testcase_32 AC 69 ms
71,176 KB
testcase_33 AC 70 ms
70,992 KB
testcase_34 AC 70 ms
71,084 KB
testcase_35 AC 69 ms
71,204 KB
testcase_36 AC 72 ms
71,036 KB
testcase_37 AC 72 ms
70,868 KB
権限があれば一括ダウンロードができます

ソースコード

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(pow(M,N,MOD))
for i in range(1,M+1):
    ans -= pow(M-i,N,MOD)*fu.choose(M,i) * (1 if i&1 else -1)
print(ans)
0