結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー googol_S0googol_S0
提出日時 2021-07-09 21:36:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 295 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 1,008 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 89,452 KB
最終ジャッジ日時 2023-09-14 08:00:11
合計ジャッジ時間 5,577 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
87,640 KB
testcase_01 AC 84 ms
87,880 KB
testcase_02 AC 277 ms
89,440 KB
testcase_03 AC 273 ms
89,384 KB
testcase_04 AC 280 ms
89,376 KB
testcase_05 AC 295 ms
89,116 KB
testcase_06 AC 295 ms
89,204 KB
testcase_07 AC 280 ms
89,316 KB
testcase_08 AC 278 ms
89,312 KB
testcase_09 AC 274 ms
89,348 KB
testcase_10 AC 286 ms
89,240 KB
testcase_11 AC 248 ms
89,244 KB
testcase_12 AC 245 ms
89,452 KB
testcase_13 AC 251 ms
89,384 KB
testcase_14 AC 93 ms
87,832 KB
testcase_15 AC 85 ms
87,792 KB
testcase_16 AC 84 ms
87,648 KB
testcase_17 AC 84 ms
87,896 KB
testcase_18 AC 85 ms
87,788 KB
testcase_19 AC 87 ms
87,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=10**9+7
def cmb(n,r):
  if r<0 or r>n:
    return 0
  return (g1[n]*g2[r]*g2[n-r])%mod

N=500000
g1=[1]*(N+3)
for i in range(2,N+3):
  g1[i]=g1[i-1]*i%mod
g2=[0]*len(g1)
g2[-1]=pow(g1[-1],mod-2,mod)
for i in range(N+1,-1,-1):
  g2[i]=g2[i+1]*(i+1)%mod
inv=[0]*(N+3)
for i in range(1,N+3):
  inv[i]=g2[i]*g1[i-1]%mod
N,M=map(int,input().split())
ANS=cmb(N+N,N)*(N+N)
for i in range(M):
  t,x,y=map(int,input().split())
  if t==1:
    ANS-=cmb(x+y,y)*cmb(N*2-x-1-y,N-y)
  else:
    ANS-=cmb(x+y,y)*cmb(N*2-x-y-1,N-y-1)
print(ANS%mod)
0