結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー osm ibtosm ibt
提出日時 2021-07-10 13:10:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 1,827 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 105,656 KB
最終ジャッジ日時 2023-09-14 18:55:34
合計ジャッジ時間 6,279 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
98,024 KB
testcase_01 AC 139 ms
97,844 KB
testcase_02 AC 308 ms
105,004 KB
testcase_03 AC 306 ms
105,052 KB
testcase_04 AC 313 ms
105,152 KB
testcase_05 AC 317 ms
105,208 KB
testcase_06 AC 312 ms
105,656 KB
testcase_07 AC 314 ms
104,788 KB
testcase_08 AC 320 ms
105,000 KB
testcase_09 AC 311 ms
104,996 KB
testcase_10 AC 315 ms
105,092 KB
testcase_11 AC 281 ms
105,144 KB
testcase_12 AC 279 ms
105,472 KB
testcase_13 AC 277 ms
105,152 KB
testcase_14 AC 70 ms
71,168 KB
testcase_15 AC 70 ms
71,268 KB
testcase_16 AC 70 ms
71,392 KB
testcase_17 AC 69 ms
71,416 KB
testcase_18 AC 70 ms
71,344 KB
testcase_19 AC 71 ms
71,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#####################################
# nCr % 10**9+7  n = 10**6
#####################################
class Combination:
    def __init__(self, mod=10**9+7):
        self.mod = mod
        self.max_n = 1
        self.factorial = [1, 1]
        self.inverse = [None, 1]
        self.f_inverse = [1, 1]

    def __preprocessing(self, max_n):
        fac = self.factorial
        inv = self.inverse
        finv = self.f_inverse
        mod = self.mod
        fac += [-1] * (max_n - self.max_n)
        inv += [-1] * (max_n - self.max_n)
        finv += [-1] * (max_n - self.max_n)
        for i in range(self.max_n + 1, max_n + 1):
            fac[i] = fac[i - 1] * i % mod
            inv[i] = mod - inv[mod % i] * (mod // i) % mod
            finv[i] = finv[i - 1] * inv[i] % mod
        self.max_n = max_n


    def fac(self, n):
        if n < 0:
            return 0
        if n > self.max_n: self.__preprocessing(n)
        return self.factorial[n]


    def nCr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        if n > self.max_n: self.__preprocessing(n)
        return self.factorial[n] * (self.f_inverse[r] * self.f_inverse[n - r] % self.mod) % self.mod


    def nPr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        if n > self.max_n: self.__preprocessing(n)
        return self.factorial[n] * self.f_inverse[n - r] % self.mod


    def nHr(self, n, r):
        return self.nCr(n-1+r, n-1)


mod = 1000000007
cmb = Combination(mod)
# cmb.nCr(n, j)



n, m = map(int, input().split())
total = (2*n*cmb.nCr(2*n, n)) % mod
for _ in range(m):
    t, x, y = map(int, input().split())
    if t == 1:
        total -= cmb.nCr(x+y, x) * cmb.nCr(2*n-x-y-1, n-x-1)
    if t == 2:
        total -= cmb.nCr(x+y, x) * cmb.nCr(2*n-x-y-1, n-x)
    total %= mod

print(total)
0