結果
| 問題 | No.1596 Distance Sum in 2D Plane | 
| コンテスト | |
| ユーザー |  taiga0629kyopro | 
| 提出日時 | 2021-07-09 22:01:06 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 286 ms / 2,000 ms | 
| コード長 | 661 bytes | 
| コンパイル時間 | 194 ms | 
| コンパイル使用メモリ | 82,176 KB | 
| 実行使用メモリ | 82,688 KB | 
| 最終ジャッジ日時 | 2024-07-01 16:23:28 | 
| 合計ジャッジ時間 | 5,221 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
ソースコード
n,m=map(int,input().split())
mod=10**9+7
#############
cnb_max=2*n+100
#############
kai=[1]*(cnb_max+1)
rkai=[1]*(cnb_max+1)
for i in range(cnb_max):
    kai[i+1]=kai[i]*(i+1)%mod
rkai[cnb_max]=pow(kai[cnb_max],mod-2,mod)
for i in range(cnb_max):
    rkai[cnb_max-1-i]=rkai[cnb_max-i]*(cnb_max-i)%mod
def cnb(x,y):
    if y>x:
        return 0
    if x<0:return 0
    if y<0:return 0
    return kai[x]*rkai[y]*rkai[x-y]%mod
ans=2*n*cnb(2*n,n)%mod
for i in range(m):
    t,x,y=map(int,input().split())
    if t==1:
        ans-=cnb(2*n-x-y-1,n-y)*cnb(x+y,y)
    else:
        ans -= cnb(2 * n - x - y - 1, n - x)*cnb(x+y,y)
    ans%=mod
print(ans)
            
            
            
        