結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-07-09 21:42:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 378 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 186,784 KB
最終ジャッジ日時 2023-09-14 08:14:52
合計ジャッジ時間 6,898 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
163,832 KB
testcase_01 AC 156 ms
163,900 KB
testcase_02 AC 378 ms
186,360 KB
testcase_03 AC 371 ms
186,304 KB
testcase_04 AC 365 ms
186,296 KB
testcase_05 AC 362 ms
186,636 KB
testcase_06 AC 361 ms
186,436 KB
testcase_07 AC 359 ms
186,224 KB
testcase_08 AC 365 ms
186,072 KB
testcase_09 AC 362 ms
186,384 KB
testcase_10 AC 370 ms
186,372 KB
testcase_11 AC 357 ms
186,784 KB
testcase_12 AC 356 ms
186,216 KB
testcase_13 AC 362 ms
186,220 KB
testcase_14 AC 70 ms
71,388 KB
testcase_15 AC 71 ms
71,052 KB
testcase_16 AC 70 ms
71,316 KB
testcase_17 AC 68 ms
71,432 KB
testcase_18 AC 69 ms
71,552 KB
testcase_19 AC 70 ms
71,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
L = [list(map(int,input().split())) for i in range(m)]

mod = 10**9+7

### for bigger prime 
fact = [1,1]
finv = [1,1]
inv = [0,1]
 
for i in range(2,n*2+5):
    fact.append((fact[-1]*i)%mod)
    inv.append((inv[mod%i]*(mod-mod//i))%mod)
    finv.append((finv[-1]*inv[-1])%mod)
 
def nCr(n,r,mod):
    if r > n:
        return 0
    else: 
        return fact[n]*finv[r]%mod*finv[n-r]%mod

ans = nCr(2*n,n,mod)*(2*n)%mod
for t,x,y in L:
    if t == 1:
        ans -= nCr(x+y,x,mod)*nCr(2*n-x-1-y,n-y,mod)
        ans %= mod
    else:
        ans -= nCr(x+y,x,mod)*nCr(2*n-x-1-y,n-x,mod)
        ans %= mod
print(ans)
0