結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー realDivineJKrealDivineJK
提出日時 2021-07-25 17:07:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 682 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 83,512 KB
最終ジャッジ日時 2023-09-28 07:01:34
合計ジャッジ時間 5,361 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
82,260 KB
testcase_01 AC 79 ms
82,256 KB
testcase_02 AC 144 ms
83,468 KB
testcase_03 AC 147 ms
83,244 KB
testcase_04 AC 143 ms
83,460 KB
testcase_05 AC 143 ms
83,252 KB
testcase_06 AC 144 ms
83,228 KB
testcase_07 AC 147 ms
83,288 KB
testcase_08 AC 144 ms
83,464 KB
testcase_09 AC 142 ms
83,404 KB
testcase_10 AC 143 ms
83,376 KB
testcase_11 AC 132 ms
83,464 KB
testcase_12 AC 129 ms
83,136 KB
testcase_13 AC 127 ms
83,512 KB
testcase_14 AC 61 ms
71,392 KB
testcase_15 AC 62 ms
71,472 KB
testcase_16 AC 62 ms
71,424 KB
testcase_17 AC 61 ms
71,108 KB
testcase_18 AC 59 ms
71,608 KB
testcase_19 AC 59 ms
71,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N, M = map(int, input().split())
mod = int(1e9) + 7
fact = [1]*(2*N+13)
invf = [1]*(2*N+13)
for i in range(2*N+12):
    fact[i+1] = (i+1)*fact[i] % mod
invf[-1] = pow(fact[-1], mod-2, mod)
for i in range(2*N+12, 0, -1):
    invf[i-1] = i * invf[i] % mod
S = 0
for _ in range(M):
    t, x, y = map(int, input().split())
    X = fact[x+y] * invf[x] % mod
    X = X * invf[y] % mod
    X = X * fact[2*N-x-y-1] % mod
    if t == 1:
        X = X * invf[N-x-1] % mod
        X = X * invf[N-y] % mod
    else:
        X = X * invf[N-x] % mod
        X = X * invf[N-y-1] % mod
    S = (S + X) % mod
print((2*N*fact[2*N] * invf[N] * invf[N] - S) % mod)
0