結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー wolgnikwolgnik
提出日時 2021-07-09 23:27:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 947 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 135,432 KB
最終ジャッジ日時 2023-09-14 10:50:43
合計ジャッジ時間 5,004 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
133,984 KB
testcase_01 AC 130 ms
133,744 KB
testcase_02 AC 238 ms
134,888 KB
testcase_03 AC 226 ms
134,900 KB
testcase_04 AC 219 ms
135,076 KB
testcase_05 AC 215 ms
135,204 KB
testcase_06 AC 217 ms
135,144 KB
testcase_07 AC 217 ms
135,204 KB
testcase_08 AC 218 ms
135,144 KB
testcase_09 AC 214 ms
135,152 KB
testcase_10 AC 218 ms
135,344 KB
testcase_11 AC 199 ms
135,432 KB
testcase_12 AC 199 ms
135,132 KB
testcase_13 AC 198 ms
135,296 KB
testcase_14 AC 70 ms
71,336 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 69 ms
71,160 KB
testcase_18 AC 69 ms
71,532 KB
testcase_19 AC 71 ms
71,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N, M = map(int, input().split())
mod = 10 ** 9 + 7

class Factorial:
  def __init__(self, n, mod):
    self.mod = mod
    self.f = [1]
    for i in range(1, n + 1): self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]: self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i): return self.f[i]
  def ifactorial(self, i): return self.i[i]
  def combi(self, n, k): return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod
  def permi(self, n, k): return self.f[n] * self.i[n - k] % self.mod

f = Factorial(N * 2, mod)
res = f.combi(N * 2, N) * (N * 2) % mod
#print(res)
for _ in range(M):
  t, x, y = map(int, input().split())
  u, v = x, y
  if t == 1: u += 1
  if t == 2: v += 1
  if u in range(N) and v in range(N):
    res -= f.combi(x + y, x) * f.combi(N * 2 - u - v, N - u) % mod
    res %= mod
print(res)
0