結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー dachengz
提出日時 2022-12-17 13:42:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 653 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 82,560 KB
最終ジャッジ日時 2024-11-16 22:05:04
合計ジャッジ時間 5,141 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7
N, M = map(int, input().split())

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

def comb(n, k):
    if n < k or k < 0 or n < 0:
        return 0
    return fac[n] * caf[k] % mod * caf[n - k] % mod

ans = N2 * comb(N2, N) % mod
for _ in range(M):
    t, x, y = map(int, input().split())
    if t == 1:
        ans = (ans - comb(x + y, x) * comb(N2 - x - y - 1, N - y)) % mod
    else:
        ans = (ans - comb(x + y, x) * comb(N2 - x - y - 1, N - x)) % mod
print(ans)
0