結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー H3PO4
提出日時 2023-03-15 12:15:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 792 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 81,952 KB
実行使用メモリ 83,076 KB
最終ジャッジ日時 2024-09-18 08:41:03
合計ジャッジ時間 5,158 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7
MAX = 4 * 10 ** 5 + 10
# https://tjkendev.github.io/procon-library/python/math/factorial.html から拝借しています。
fact = [1] * (MAX + 1)
rfact = [1] * (MAX + 1)
r = 1
for i in range(1, MAX + 1):
    fact[i] = r = r * i % MOD
rfact[MAX] = r = pow(fact[MAX], MOD - 2, MOD)
for i in range(MAX, 0, -1):
    rfact[i - 1] = r = r * i % MOD


def comb(n, k, error=0):
    if not 0 <= k <= n:
        return error
    return fact[n] * rfact[k] * rfact[n - k] % MOD


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