結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー tassei903tassei903
提出日時 2021-07-09 22:43:52
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 445 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 259,528 KB
最終ジャッジ日時 2023-09-14 10:21:02
合計ジャッジ時間 10,223 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 286 ms
259,372 KB
testcase_01 AC 292 ms
259,456 KB
testcase_02 AC 430 ms
259,528 KB
testcase_03 AC 444 ms
259,172 KB
testcase_04 AC 443 ms
259,392 KB
testcase_05 AC 438 ms
259,320 KB
testcase_06 AC 445 ms
259,336 KB
testcase_07 AC 433 ms
259,340 KB
testcase_08 AC 423 ms
259,392 KB
testcase_09 AC 427 ms
259,292 KB
testcase_10 AC 426 ms
259,492 KB
testcase_11 AC 396 ms
259,372 KB
testcase_12 AC 396 ms
259,288 KB
testcase_13 AC 399 ms
259,364 KB
testcase_14 AC 300 ms
259,324 KB
testcase_15 AC 282 ms
259,240 KB
testcase_16 AC 293 ms
259,212 KB
testcase_17 AC 291 ms
259,308 KB
testcase_18 AC 289 ms
259,304 KB
testcase_19 AC 293 ms
259,260 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