結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー tassei903tassei903
提出日時 2021-07-09 23:22:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 423 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 87,340 KB
実行使用メモリ 259,448 KB
最終ジャッジ日時 2023-09-14 10:50:03
合計ジャッジ時間 8,945 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 270 ms
259,448 KB
testcase_01 AC 265 ms
259,100 KB
testcase_02 AC 423 ms
259,276 KB
testcase_03 AC 408 ms
259,276 KB
testcase_04 AC 411 ms
259,120 KB
testcase_05 AC 394 ms
259,256 KB
testcase_06 AC 396 ms
259,252 KB
testcase_07 AC 394 ms
259,220 KB
testcase_08 AC 393 ms
259,260 KB
testcase_09 AC 388 ms
259,272 KB
testcase_10 AC 402 ms
259,148 KB
testcase_11 AC 384 ms
259,312 KB
testcase_12 AC 388 ms
259,224 KB
testcase_13 AC 388 ms
259,284 KB
testcase_14 AC 276 ms
259,328 KB
testcase_15 AC 278 ms
259,152 KB
testcase_16 AC 270 ms
259,076 KB
testcase_17 AC 271 ms
259,224 KB
testcase_18 AC 273 ms
259,440 KB
testcase_19 AC 271 ms
259,148 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