結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー |
|
提出日時 | 2022-03-15 19:25:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 268 ms / 2,000 ms |
コード長 | 624 bytes |
コンパイル時間 | 500 ms |
コンパイル使用メモリ | 82,160 KB |
実行使用メモリ | 82,964 KB |
最終ジャッジ日時 | 2024-09-22 11:35:13 |
合計ジャッジ時間 | 6,412 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
N,M = map(int,input().split()) P = 10 ** 9 + 7 C = N + N + 3 fact = [1] * C fact_inv = [1] * C for i in range(2,C): fact[i] = fact[i-1] * i % P fact_inv[-1] = pow(fact[-1],P-2,P) for i in range(C-2,0,-1): fact_inv[i] = fact_inv[i+1] * (i + 1) % P def comb(n,k): return fact[n] * fact_inv[k] * fact_inv[n-k] % P ans = comb(N + N,N) * (N + N) % P for _ in range(M): t,x,y = map(int,input().split()) if t == 1: tmp = comb(x+y,x) * comb(N-x-1+N-y,N-y) % P ans = (ans - tmp) % P else: tmp = comb(x+y,x) * comb(N - x + N - y - 1,N - x) % P ans = (ans - tmp) % P print(ans)