結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー rlangevinrlangevin
提出日時 2023-06-22 00:15:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 748 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 85,172 KB
最終ジャッジ日時 2023-09-11 19:18:34
合計ジャッジ時間 4,859 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
83,620 KB
testcase_01 AC 85 ms
83,640 KB
testcase_02 AC 217 ms
84,864 KB
testcase_03 AC 226 ms
85,048 KB
testcase_04 AC 225 ms
84,804 KB
testcase_05 AC 230 ms
84,996 KB
testcase_06 AC 224 ms
84,832 KB
testcase_07 AC 217 ms
84,960 KB
testcase_08 AC 222 ms
84,956 KB
testcase_09 AC 215 ms
84,996 KB
testcase_10 AC 211 ms
84,764 KB
testcase_11 AC 177 ms
85,172 KB
testcase_12 AC 176 ms
85,152 KB
testcase_13 AC 179 ms
84,952 KB
testcase_14 AC 84 ms
83,796 KB
testcase_15 AC 85 ms
83,720 KB
testcase_16 AC 85 ms
83,644 KB
testcase_17 AC 85 ms
83,832 KB
testcase_18 AC 83 ms
83,616 KB
testcase_19 AC 84 ms
83,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, M = map(int, input().split())

mod = 10 ** 9 + 7
n = 505050
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod


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