結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー |
![]() |
提出日時 | 2021-07-09 22:13:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 157 ms / 2,000 ms |
コード長 | 3,186 bytes |
コンパイル時間 | 397 ms |
コンパイル使用メモリ | 82,664 KB |
実行使用メモリ | 82,448 KB |
最終ジャッジ日時 | 2024-07-01 16:45:38 |
合計ジャッジ時間 | 3,573 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
import sysMOD = 10**9 + 7def main():input = sys.stdin.readlineN, M = map(int, input().split())fu = FactorialUtils(N + N)ans = Mint(fu.choose(N + N, N))ans *= N + Nfor _ in range(M):t, x, y = map(int, input().split())if t == 1:ans -= fu.choose(x + y, x) * fu.choose(N + N - x - y - 1, N - y)else:ans -= fu.choose(x + y, x) * fu.choose(N + N - x - y - 1, N - x)print(ans)class Mint:__slots__ = ('value')def __init__(self, value=0) -> None:self.value = int(value) % MODdef inverse(self) -> int: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) -> str: return str(self.value)def __int__(self) -> int: return self.valuedef __eq__(self, other) -> bool: return self.value == other.valuedef __neg__(self) -> 'Mint': return Mint(-self.value)def __hash__(self) -> int: return hash(self.value)def __bool__(self) -> bool: return self.value != 0def __iadd__(self, other) -> 'Mint':self.value = (self.value + int(other)) % MODreturn selfdef __add__(self, other) -> 'Mint':new_obj = Mint(self.value + int(other))return new_obj__radd__ = __add__def __isub__(self, other) -> 'Mint':self.value = (self.value - int(other)) % MODreturn selfdef __sub__(self, other) -> 'Mint':new_obj = Mint(self.value - int(other))return new_objdef __rsub__(self, other) -> 'Mint':new_obj = Mint(int(other) - self.value)return new_objdef __imul__(self, other) -> 'Mint':self.value = self.value * int(other) % MODreturn selfdef __mul__(self, other) -> 'Mint':new_obj = Mint(self.value * int(other))return new_obj__rmul__ = __mul__def __ifloordiv__(self, other) -> 'Mint':other = other if isinstance(other, Mint) else Mint(other)self *= other.inverse()return selfdef __floordiv__(self, other) -> 'Mint':new_obj = Mint(self.value)new_obj //= otherreturn new_objdef __rfloordiv__(self, other) -> 'Mint':new_obj = Mint(int(other))new_obj //= selfreturn new_objclass FactorialUtils:__slots__ = ('fac', 'ifac')def __init__(self, n):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 % 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] % MOD) * self.ifac[r] % MODdef multichoose(self, u, k):return (self.fac[u + k - 1] * self.ifac[u - 1] % MOD) * self.ifac[k] % MODdef permutation(self, n, r):if r < 0 or r > n: return 0return self.fac[n] * self.ifac[n - r] % MODif __name__ == '__main__':main()