結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2021-08-26 22:33:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 737 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 128,648 KB
最終ジャッジ日時 2024-04-29 16:04:15
合計ジャッジ時間 27,226 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,564 ms
128,516 KB
testcase_01 AC 1,520 ms
128,388 KB
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 AC 1,613 ms
128,648 KB
testcase_15 AC 1,629 ms
128,648 KB
testcase_16 AC 1,612 ms
128,648 KB
testcase_17 AC 1,591 ms
128,388 KB
testcase_18 AC 1,572 ms
128,644 KB
testcase_19 AC 1,516 ms
128,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

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)
N,M = map(int,input().split())

ans = cmb(2*N,N,p)*2*N
ans %= p
for i in range(M):
  t,x,y = map(int,input().split())
  if t == 1:
    ans -= cmb(x+y,x,p)*cmb(2*N-x-y-1,N-y,p)
  else:
    x,y = y,x
    ans -= cmb(x+y,x,p)*cmb(2*N-x-y-1,N-y,p)
print(ans%p)  
0