結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー rlangevinrlangevin
提出日時 2023-06-22 00:15:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 744 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 85,016 KB
最終ジャッジ日時 2023-09-11 19:17:54
合計ジャッジ時間 6,074 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 84 ms
83,768 KB
testcase_02 AC 229 ms
84,692 KB
testcase_03 AC 230 ms
84,692 KB
testcase_04 AC 223 ms
84,976 KB
testcase_05 AC 222 ms
84,912 KB
testcase_06 AC 215 ms
84,884 KB
testcase_07 AC 223 ms
84,904 KB
testcase_08 AC 217 ms
84,944 KB
testcase_09 AC 207 ms
85,004 KB
testcase_10 AC 212 ms
84,828 KB
testcase_11 AC 182 ms
84,920 KB
testcase_12 AC 179 ms
84,904 KB
testcase_13 AC 178 ms
85,016 KB
testcase_14 AC 88 ms
83,532 KB
testcase_15 AC 85 ms
83,844 KB
testcase_16 AC 85 ms
83,532 KB
testcase_17 AC 85 ms
83,780 KB
testcase_18 AC 86 ms
83,808 KB
testcase_19 AC 87 ms
83,792 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)
0