結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2021-08-26 22:34:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 739 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 69,768 KB
最終ジャッジ日時 2024-04-29 16:05:08
合計ジャッジ時間 32,797 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 766 ms
69,516 KB
testcase_01 AC 743 ms
69,636 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 AC 1,842 ms
69,512 KB
testcase_12 AC 1,820 ms
69,504 KB
testcase_13 AC 1,839 ms
69,508 KB
testcase_14 AC 774 ms
69,512 KB
testcase_15 AC 740 ms
69,508 KB
testcase_16 AC 775 ms
69,640 KB
testcase_17 AC 779 ms
69,636 KB
testcase_18 AC 777 ms
69,512 KB
testcase_19 AC 792 ms
69,640 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 = 5*10 ** 5  # 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