結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー AEnAEn
提出日時 2023-07-12 00:07:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 484 ms / 2,000 ms
コード長 523 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 86,416 KB
実行使用メモリ 83,588 KB
最終ジャッジ日時 2023-10-11 14:58:56
合計ジャッジ時間 10,142 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 354 ms
82,408 KB
testcase_01 AC 349 ms
82,356 KB
testcase_02 AC 479 ms
83,336 KB
testcase_03 AC 475 ms
83,356 KB
testcase_04 AC 477 ms
83,284 KB
testcase_05 AC 468 ms
83,036 KB
testcase_06 AC 477 ms
83,300 KB
testcase_07 AC 473 ms
83,252 KB
testcase_08 AC 484 ms
83,376 KB
testcase_09 AC 476 ms
83,484 KB
testcase_10 AC 484 ms
83,352 KB
testcase_11 AC 448 ms
83,588 KB
testcase_12 AC 443 ms
83,524 KB
testcase_13 AC 443 ms
83,260 KB
testcase_14 AC 71 ms
71,280 KB
testcase_15 AC 71 ms
71,172 KB
testcase_16 AC 71 ms
71,244 KB
testcase_17 AC 70 ms
71,208 KB
testcase_18 AC 71 ms
71,288 KB
testcase_19 AC 77 ms
71,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod = 10**9+7
N, M = map(int,input().split())
fac = [1]*(2*N+1)
inv = [1]*(2*N+1)
for i in range(1,2*N+1):
    fac[i] = (fac[i-1]*i)%mod
    inv[i] = (inv[i-1]*pow(i,mod-2,mod))%mod

def ncr(n,r):
    return fac[n]*inv[r]*inv[n-r]%mod

ans = ncr(2*N,N)*2*N%mod
for i in range(M):
    t,x,y = map(int, input().split())
    if t==1:
        ans -= ncr(x+y,x)*ncr(N-(x+1)+N-y,N-y)
        ans %= mod
    else:
        ans -= ncr(x+y,x)*ncr(N-x+N-(y+1),N-x)
        ans %= mod
print(ans)
0