結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー wolgnikwolgnik
提出日時 2021-07-09 22:11:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 941 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 135,524 KB
最終ジャッジ日時 2023-09-14 09:19:18
合計ジャッジ時間 5,366 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 129 ms
134,020 KB
testcase_02 AC 220 ms
135,420 KB
testcase_03 AC 227 ms
135,344 KB
testcase_04 AC 221 ms
135,232 KB
testcase_05 AC 223 ms
135,280 KB
testcase_06 AC 217 ms
135,292 KB
testcase_07 AC 218 ms
135,180 KB
testcase_08 AC 219 ms
135,524 KB
testcase_09 AC 213 ms
135,240 KB
testcase_10 AC 212 ms
135,300 KB
testcase_11 AC 196 ms
135,260 KB
testcase_12 AC 197 ms
135,316 KB
testcase_13 AC 197 ms
135,424 KB
testcase_14 AC 69 ms
71,528 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 68 ms
71,412 KB
testcase_18 AC 68 ms
71,692 KB
testcase_19 AC 71 ms
71,392 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)
#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