結果
| 問題 |
No.1596 Distance Sum in 2D Plane
|
| コンテスト | |
| ユーザー |
ayaoni
|
| 提出日時 | 2021-07-09 21:35:49 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 221 ms / 2,000 ms |
| コード長 | 1,353 bytes |
| コンパイル時間 | 152 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 82,560 KB |
| 最終ジャッジ日時 | 2024-07-01 15:25:18 |
| 合計ジャッジ時間 | 4,116 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())
class counting():
def __init__(self,N,p):
self.p = p
self.fac = [1]*(N+1)
for i in range(1,N+1):
self.fac[i] = (self.fac[i-1]*i) % self.p
self.fac_inv = [0]*(N+1)
a = pow(self.fac[-1],self.p-2,self.p)
for i in range(N,-1,-1):
self.fac_inv[i] = a
a *= i
a %= self.p
def perm(self,n,r):
if n < r:
return 0
return (self.fac[n]*self.fac_inv[n-r]) % self.p
def comb(self,n,r):
if n < r:
return 0
return (self.fac[n]*self.fac_inv[n-r]*self.fac_inv[r]) % self.p
N,M = MI()
mod = 10**9+7
C = counting(2*N,mod)
ans = 2*N*C.comb(2*N,N)
ans %= mod
for _ in range(M):
t,x,y = MI()
if t == 1:
ans -= C.comb(x+y,x)*C.comb(2*N-(x+y+1),N-y)
else:
ans -= C.comb(x+y,x)*C.comb(2*N-(x+y+1),N-x)
ans %= mod
print(ans)
ayaoni