結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー tassei903tassei903
提出日時 2021-07-09 22:43:52
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 445 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 272 ms
使用メモリ 255,484 KB
最終ジャッジ日時 2023-02-02 00:44:59
合計ジャッジ時間 8,861 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 248 ms
255,344 KB
testcase_01 AC 252 ms
255,484 KB
testcase_02 AC 445 ms
255,348 KB
testcase_03 AC 408 ms
255,152 KB
testcase_04 AC 409 ms
255,024 KB
testcase_05 AC 395 ms
255,340 KB
testcase_06 AC 402 ms
255,200 KB
testcase_07 AC 395 ms
255,208 KB
testcase_08 AC 396 ms
255,244 KB
testcase_09 AC 396 ms
255,260 KB
testcase_10 AC 393 ms
255,316 KB
testcase_11 AC 382 ms
255,308 KB
testcase_12 AC 377 ms
255,324 KB
testcase_13 AC 381 ms
255,376 KB
testcase_14 AC 253 ms
255,424 KB
testcase_15 AC 251 ms
255,420 KB
testcase_16 AC 251 ms
254,968 KB
testcase_17 AC 253 ms
255,248 KB
testcase_18 AC 252 ms
255,408 KB
testcase_19 AC 252 ms
255,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
sys.setrecursionlimit(10**7)
yes = lambda :print("yes");Yes = lambda :print("Yes")
no = lambda :print("no");No = lambda :print("No")
#######################################################################

n, m = na()

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return ((fact[n] * factinv[r])%p) * factinv[n-r] % p

ans = n*2*cmb(2*n,n)%p

for i in range(m):
    t,x,y = na()
    if t == 1:
        ans-=cmb(x+y,x)*cmb(2*n-x-y-1,n-y)%p
        ans%=p
    else:
        ans-=cmb(x+y,x)*cmb(2*n-x-y-1,n-x)%p
        ans%=p
print(ans)
0