結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー googol_S0googol_S0
提出日時 2021-07-09 21:36:06
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 459 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 270 ms
使用メモリ 94,116 KB
最終ジャッジ日時 2023-02-01 22:23:56
合計ジャッジ時間 8,076 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 108 ms
92,068 KB
testcase_01 AC 108 ms
92,152 KB
testcase_02 AC 444 ms
93,952 KB
testcase_03 AC 459 ms
93,936 KB
testcase_04 AC 453 ms
93,932 KB
testcase_05 AC 438 ms
93,740 KB
testcase_06 AC 426 ms
93,876 KB
testcase_07 AC 427 ms
93,740 KB
testcase_08 AC 421 ms
94,116 KB
testcase_09 AC 429 ms
94,064 KB
testcase_10 AC 421 ms
93,748 KB
testcase_11 AC 388 ms
93,920 KB
testcase_12 AC 385 ms
93,772 KB
testcase_13 AC 384 ms
94,028 KB
testcase_14 AC 107 ms
92,392 KB
testcase_15 AC 109 ms
92,244 KB
testcase_16 AC 110 ms
92,236 KB
testcase_17 AC 111 ms
92,288 KB
testcase_18 AC 108 ms
92,028 KB
testcase_19 AC 108 ms
92,536 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