結果
| 問題 | No.1596 Distance Sum in 2D Plane | 
| コンテスト | |
| ユーザー |  ntuda | 
| 提出日時 | 2021-07-22 18:53:52 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 416 ms / 2,000 ms | 
| コード長 | 580 bytes | 
| コンパイル時間 | 202 ms | 
| コンパイル使用メモリ | 82,368 KB | 
| 実行使用メモリ | 102,740 KB | 
| 最終ジャッジ日時 | 2024-07-17 15:03:09 | 
| 合計ジャッジ時間 | 7,058 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
ソースコード
N,M = map(int,input().split())
TXY = [list(map(int,input().split())) for _ in range(M)]
mod = 10 ** 9 + 7
L1 = [1] * (N * 2 + 1)
L2 = [1] * (N + 1)
for i in range(2,N*2+1):
    L1[i] = (i*L1[i-1]) % mod
for i in range(2,N+1):
    L2[i] = (L2[i-1] * pow(i,-1,mod)) % mod
ans =  (L1[2 * N] * L2[N] * L2[N] * (2*N)) % mod
for txy in TXY:
    t,x,y = txy
    temp = (L1[x+y] * L2[x] * L2[y])%mod
    if t == 1:
        temp = (temp*L1[2*N-x-y-1] * L2[N-x-1] * L2[N-y])%mod
    else:
        temp = (temp*L1[2*N-x-y-1] * L2[N-x] * L2[N-y-1])%mod
    ans = (ans-temp)%mod
print(ans)
            
            
            
        