結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー minimumminimum
提出日時 2021-07-09 21:57:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 655 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 87,220 KB
最終ジャッジ日時 2023-09-14 08:52:33
合計ジャッジ時間 6,143 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
85,548 KB
testcase_01 AC 106 ms
85,728 KB
testcase_02 AC 325 ms
86,936 KB
testcase_03 AC 320 ms
86,908 KB
testcase_04 AC 320 ms
86,768 KB
testcase_05 AC 316 ms
87,072 KB
testcase_06 AC 317 ms
86,960 KB
testcase_07 AC 324 ms
87,220 KB
testcase_08 AC 320 ms
86,864 KB
testcase_09 AC 319 ms
87,020 KB
testcase_10 AC 319 ms
86,880 KB
testcase_11 AC 267 ms
87,196 KB
testcase_12 AC 264 ms
86,932 KB
testcase_13 AC 264 ms
87,040 KB
testcase_14 AC 77 ms
71,224 KB
testcase_15 AC 75 ms
71,448 KB
testcase_16 AC 72 ms
71,348 KB
testcase_17 AC 72 ms
71,292 KB
testcase_18 AC 73 ms
71,252 KB
testcase_19 AC 74 ms
71,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
mod = 10 ** 9 + 7

fact = [1 for i in range(2 * n + 1)]
inv = [1 for i in range(2 * n + 1)]
fact_inv = [1 for i in range(2 * n + 1)]
for i in range(2, 2 * n + 1):
    fact[i] = (fact[i - 1] * i) % mod
    inv[i]  = ((- inv[mod % (i)]) * (mod // i)) % mod
    fact_inv[i] = (fact_inv[i - 1] * inv[i]) % mod

def c(x, y):
    return (fact[x + y] * fact_inv[x] * fact_inv[y]) % mod

ans = (c(n, n) * 2 * n) % mod

for i in range(m):
    t, x, y = map(int, input().split())
    if t == 1:
        ans = (ans - c(x, y) * c(n - y, n - 1 - x)) % mod
    else:
        ans = (ans - c(x, y) * c(n - x, n - 1 - y)) % mod

print(ans)
0