結果
問題 | No.1035 Color Box |
ユーザー |
![]() |
提出日時 | 2020-04-24 23:45:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 102 ms / 2,000 ms |
コード長 | 2,799 bytes |
コンパイル時間 | 255 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 66,944 KB |
最終ジャッジ日時 | 2024-10-15 03:56:48 |
合計ジャッジ時間 | 3,501 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
N,M=map(int, input().split())class FactorialUtils:def __init__(self, n, mod=10**9+7):self.__mod = modself.fac = [1] * (n+1)self.ifac = [1] * (n+1)for i in range(2, n+1): self.fac[i] = self.fac[i-1] * i % modself.ifac[n] = pow(self.fac[n], mod-2, mod)for i in range(n, 1, -1): self.ifac[i-1] = self.ifac[i] * i % moddef choose(self, n, r):if r < 0 or r > n: return 0return (self.fac[n] * self.ifac[n-r] % self.__mod) * self.ifac[r] % self.__moddef multichoose(self, u, k):return (self.fac[u+k-1] * self.ifac[u-1] % self.__mod) * self.ifac[k] %self.__modMOD = 10**9+7class Mint:def __init__(self, value=0):self.value = value % MODif self.value < 0: self.value += MOD@staticmethoddef get_value(x): return x.value if isinstance(x, Mint) else xdef inverse(self):a, b = self.value, MODu, v = 1, 0while b:t = a // bb, a = a - t * b, bv, u = u - t * v, vif u < 0: u += MODreturn udef __repr__(self): return str(self.value)def __eq__(self, other): return self.value == other.valuedef __neg__(self): return Mint(-self.value)def __hash__(self): return hash(self.value)def __bool__(self): return self.value != 0def __iadd__(self, other):self.value = (self.value + Mint.get_value(other)) % MODreturn selfdef __add__(self, other):new_obj = Mint(self.value)new_obj += otherreturn new_obj__radd__ = __add__def __isub__(self, other):self.value = (self.value - Mint.get_value(other)) % MODif self.value < 0: self.value += MODreturn selfdef __sub__(self, other):new_obj = Mint(self.value)new_obj -= otherreturn new_objdef __rsub__(self, other):new_obj = Mint(Mint.get_value(other))new_obj -= selfreturn new_objdef __imul__(self, other):self.value = self.value * Mint.get_value(other) % MODreturn selfdef __mul__(self, other):new_obj = Mint(self.value)new_obj *= otherreturn new_obj__rmul__ = __mul__def __ifloordiv__(self, other):other = other if isinstance(other, Mint) else Mint(other)self *= other.inverse()return selfdef __floordiv__(self, other):new_obj = Mint(self.value)new_obj //= otherreturn new_objdef __rfloordiv__(self, other):new_obj = Mint(Mint.get_value(other))new_obj //= selfreturn new_objfu=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)