結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー | w0mbat |
提出日時 | 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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
66,880 KB |
testcase_01 | AC | 54 ms
66,588 KB |
testcase_02 | AC | 157 ms
82,160 KB |
testcase_03 | AC | 152 ms
82,200 KB |
testcase_04 | AC | 152 ms
82,280 KB |
testcase_05 | AC | 149 ms
82,160 KB |
testcase_06 | AC | 144 ms
81,848 KB |
testcase_07 | AC | 146 ms
81,864 KB |
testcase_08 | AC | 144 ms
81,732 KB |
testcase_09 | AC | 144 ms
81,848 KB |
testcase_10 | AC | 144 ms
82,164 KB |
testcase_11 | AC | 126 ms
82,036 KB |
testcase_12 | AC | 126 ms
81,956 KB |
testcase_13 | AC | 120 ms
82,448 KB |
testcase_14 | AC | 40 ms
52,944 KB |
testcase_15 | AC | 40 ms
53,968 KB |
testcase_16 | AC | 39 ms
53,116 KB |
testcase_17 | AC | 40 ms
53,800 KB |
testcase_18 | AC | 39 ms
53,488 KB |
testcase_19 | AC | 40 ms
53,084 KB |
ソースコード
import sys MOD = 10**9 + 7 def main(): input = sys.stdin.readline N, M = map(int, input().split()) fu = FactorialUtils(N + N) ans = Mint(fu.choose(N + N, N)) ans *= N + N for _ 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) % MOD def inverse(self) -> int: 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) -> str: return str(self.value) def __int__(self) -> int: return self.value def __eq__(self, other) -> bool: return self.value == other.value def __neg__(self) -> 'Mint': return Mint(-self.value) def __hash__(self) -> int: return hash(self.value) def __bool__(self) -> bool: return self.value != 0 def __iadd__(self, other) -> 'Mint': self.value = (self.value + int(other)) % MOD return self def __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)) % MOD return self def __sub__(self, other) -> 'Mint': new_obj = Mint(self.value - int(other)) return new_obj def __rsub__(self, other) -> 'Mint': new_obj = Mint(int(other) - self.value) return new_obj def __imul__(self, other) -> 'Mint': self.value = self.value * int(other) % MOD return self def __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 self def __floordiv__(self, other) -> 'Mint': new_obj = Mint(self.value) new_obj //= other return new_obj def __rfloordiv__(self, other) -> 'Mint': new_obj = Mint(int(other)) new_obj //= self return new_obj class 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 % 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] % MOD) * self.ifac[r] % MOD def multichoose(self, u, k): return (self.fac[u + k - 1] * self.ifac[u - 1] % MOD) * self.ifac[k] % MOD def permutation(self, n, r): if r < 0 or r > n: return 0 return self.fac[n] * self.ifac[n - r] % MOD if __name__ == '__main__': main()