結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー titia
提出日時 2025-05-12 06:00:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 642 bytes
コンパイル時間 3,718 ms
コンパイル使用メモリ 82,652 KB
実行使用メモリ 245,788 KB
最終ジャッジ日時 2025-05-12 06:00:56
合計ジャッジ時間 8,045 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline


mod=10**9+7

FACT=[1]
for i in range(1,2*10**6+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(2*10**6,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]%mod*FACT_INV[a-b]%mod
    else:
        return 0

N,M=map(int,input().split())

ANS=Combi(N+N,N)*N*2


for i in range(M):
    t,x,y=map(int,input().split())

    if t==1:
        ANS-=Combi(x+y,x)*Combi((N-x-1)+(N-y),N-x-1)%mod
    else:
        ANS-=Combi(x+y,x)*Combi((N-x)+(N-y-1),N-y-1)%mod

    ANS%=mod

print(ANS%mod)
0