結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-07-11 19:38:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,230 ms / 2,000 ms
コード長 1,142 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 39,696 KB
最終ジャッジ日時 2023-09-14 20:18:49
合計ジャッジ時間 16,102 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 184 ms
39,584 KB
testcase_01 AC 177 ms
39,608 KB
testcase_02 AC 1,225 ms
39,520 KB
testcase_03 AC 1,228 ms
39,504 KB
testcase_04 AC 1,223 ms
39,568 KB
testcase_05 AC 1,229 ms
39,516 KB
testcase_06 AC 1,214 ms
39,600 KB
testcase_07 AC 1,216 ms
39,508 KB
testcase_08 AC 1,223 ms
39,636 KB
testcase_09 AC 1,230 ms
39,516 KB
testcase_10 AC 1,230 ms
39,532 KB
testcase_11 AC 976 ms
39,528 KB
testcase_12 AC 977 ms
39,696 KB
testcase_13 AC 968 ms
39,620 KB
testcase_14 AC 16 ms
8,292 KB
testcase_15 AC 16 ms
8,184 KB
testcase_16 AC 17 ms
8,224 KB
testcase_17 AC 16 ms
8,308 KB
testcase_18 AC 16 ms
8,260 KB
testcase_19 AC 17 ms
8,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#nCrなど
mod = 10 ** 9 + 7
class Combinatorics:
    def __init__(self, n):
        self.n = n
        self.fa = [1] * (self.n * 2 + 1)
        self.fi = [1] * (self.n * 2 + 1)

        for i in range(1, self.n * 2 + 1):
            self.fa[i] = self.fa[i - 1] * i % mod

        self.fi[-1] = pow(self.fa[-1], mod - 2, mod)

        for i in range(self.n * 2, 0, -1):
            self.fi[i - 1] = self.fi[i] * i % mod

    def comb(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod

    def perm(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[n - r] % mod
        
    def combr(self, n, r):
        if n == r == 0:return 1
        return self.comb(n + r - 1, r)

n, m = map(int, input().split())

C = Combinatorics(n)

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