結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-04-24 01:08:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 418 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 189,956 KB
最終ジャッジ日時 2023-09-07 16:30:03
合計ジャッジ時間 9,061 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
187,988 KB
testcase_01 AC 177 ms
188,096 KB
testcase_02 AC 411 ms
189,956 KB
testcase_03 AC 403 ms
189,924 KB
testcase_04 AC 405 ms
189,528 KB
testcase_05 AC 385 ms
189,504 KB
testcase_06 AC 387 ms
189,776 KB
testcase_07 AC 385 ms
189,756 KB
testcase_08 AC 391 ms
189,652 KB
testcase_09 AC 386 ms
189,744 KB
testcase_10 AC 392 ms
189,768 KB
testcase_11 AC 364 ms
189,344 KB
testcase_12 AC 365 ms
189,768 KB
testcase_13 AC 364 ms
189,840 KB
testcase_14 AC 178 ms
188,056 KB
testcase_15 AC 176 ms
188,492 KB
testcase_16 AC 176 ms
188,408 KB
testcase_17 AC 177 ms
188,152 KB
testcase_18 AC 180 ms
188,328 KB
testcase_19 AC 178 ms
188,052 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