結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー NSNS
提出日時 2021-07-10 14:02:19
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,691 bytes
コンパイル時間 956 ms
コンパイル使用メモリ 86,660 KB
実行使用メモリ 82,920 KB
最終ジャッジ日時 2023-09-14 19:11:04
合計ジャッジ時間 4,878 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 94 ms
80,664 KB
testcase_15 AC 94 ms
80,264 KB
testcase_16 AC 95 ms
80,208 KB
testcase_17 AC 92 ms
80,256 KB
testcase_18 AC 94 ms
80,240 KB
testcase_19 AC 96 ms
80,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import comb


class Combination:
    def __init__(self, n_max=10**6, mod=10**9+7):
        # self._n_max = n_max
        self._fac, self._finv, self._inv = [0]*n_max, [0]*n_max, [0]*n_max
        self._fac[0], self._fac[1] = 1, 1
        self._finv[0], self._finv[1] = 1, 1
        self._inv[1] = 1
        self._mod = mod
        for i in range(2, n_max):
            self._fac[i] = self._fac[i - 1] * i % self._mod
            self._inv[i] = self._mod - self._inv[self._mod%i] * (self._mod // i) % self._mod
            self._finv[i] = self._finv[i - 1] * self._inv[i] % self._mod
    def com(self, n, r):
        if n < r: return 0
        if n < 0 or r < 0: return 0
        return self._fac[n] * (self._finv[r] * self._finv[n - r] % self._mod) % self._mod

    def perm(self,n,r):
        if n < r: return 0
        if n < 0 or r < 0: return 0
        return self._fac[n] * (self._finv[n-r] % self._mod) % self._mod

    def lucas(self, n, r): # nCr (mod self._mod(prime)) 
        if n < r: return 0 
        res = 1
        while n > 0:
            nq, rq = n//self._mod, r//self._mod
            nr, rr = n-nq*self._mod, r-rq*self._mod
            res *= self.com(nr, rr)
            res %= self._mod
            n, r = nq, rq
        return res

MOD=10**9+7
comb=Combination(2*10**5+10,MOD)

n,m=map(int, input().split())
dist=n*2
pat=comb.com(2*n,n)
ans=dist*pat

for _ in range(m):
    t,x,y=map(int, input().split())
    if t==1:
        pat1=comb.com(x+y,x)
        pat2=comb.com(2*n-(x+y+1),n-y)
        ans-=pat1*pat2
        ans%=MOD
    if t==2:
        pat1=comb.com(x+y,x)
        pat2=comb.com(2*n-(x+y+1),n-x)
        ans-=pat1*pat2
        ans%=MOD
print(ans)
0