結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー minimumminimum
提出日時 2021-07-09 23:43:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 655 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 87,324 KB
最終ジャッジ日時 2023-09-14 11:03:16
合計ジャッジ時間 5,823 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
85,616 KB
testcase_01 AC 100 ms
85,608 KB
testcase_02 AC 309 ms
87,124 KB
testcase_03 AC 309 ms
87,224 KB
testcase_04 AC 324 ms
86,828 KB
testcase_05 AC 305 ms
87,324 KB
testcase_06 AC 305 ms
86,880 KB
testcase_07 AC 301 ms
86,964 KB
testcase_08 AC 300 ms
87,140 KB
testcase_09 AC 294 ms
87,140 KB
testcase_10 AC 296 ms
86,968 KB
testcase_11 AC 246 ms
87,092 KB
testcase_12 AC 248 ms
87,120 KB
testcase_13 AC 262 ms
87,144 KB
testcase_14 AC 65 ms
71,648 KB
testcase_15 AC 68 ms
71,456 KB
testcase_16 AC 67 ms
71,552 KB
testcase_17 AC 67 ms
71,428 KB
testcase_18 AC 66 ms
71,388 KB
testcase_19 AC 68 ms
71,364 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