結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー とりゐとりゐ
提出日時 2023-04-18 22:22:36
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 827 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 82,944 KB
最終ジャッジ日時 2024-04-21 23:42:35
合計ジャッジ時間 3,793 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 53 ms
64,768 KB
testcase_15 AC 53 ms
64,896 KB
testcase_16 AC 54 ms
64,512 KB
testcase_17 AC 53 ms
64,996 KB
testcase_18 AC 53 ms
64,640 KB
testcase_19 AC 53 ms
64,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
input=lambda :stdin.readline()[:-1]

mod=10**9+7
table_size=10**5*4-1

fac=[1]*(table_size+1)
finv=[1]*(table_size+1)

for i in range(2,table_size+1):
  fac[i]=fac[i-1]*i%mod
finv[table_size]=pow(fac[table_size],mod-2,mod)
for i in range(table_size-1,-1,-1):
  finv[i]=finv[i+1]*(i+1)%mod

def binom(n,k):
  if n<0 or k<0:
    return 0
  if k>n:
    return 0
  return (fac[n]*finv[k]%mod)*finv[n-k]%mod

def inv(a):
  if a<table_size:
    return fac[a-1]*finv[a]%mod
  b,u,v=mod,1,0
  while b:
    t=a//b
    a,b=b,a-t*b
    u,v=v,u-t*v
  return u%mod

n,m=map(int,input().split())
ans=0
for i in range(m):
  t,x,y=map(int,input().split())
  if t==1:
    ans-=binom(x+y,x)*binom(2*n-(x+y+1),n-(x+1))
  else:
    ans-=binom(x+y,x)*binom(2*n-(x+y+1),n-(y+1))
  ans%=mod

ans+=binom(2*n,n)*2*n
print(ans%mod)
0