結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-07-11 19:37:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 1,142 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 86,836 KB
実行使用メモリ 83,788 KB
最終ジャッジ日時 2023-09-14 20:18:32
合計ジャッジ時間 5,214 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
81,752 KB
testcase_01 AC 78 ms
81,892 KB
testcase_02 AC 259 ms
83,764 KB
testcase_03 AC 246 ms
83,772 KB
testcase_04 AC 241 ms
83,700 KB
testcase_05 AC 228 ms
83,568 KB
testcase_06 AC 236 ms
83,524 KB
testcase_07 AC 235 ms
83,352 KB
testcase_08 AC 234 ms
83,552 KB
testcase_09 AC 237 ms
83,300 KB
testcase_10 AC 238 ms
83,464 KB
testcase_11 AC 209 ms
83,632 KB
testcase_12 AC 207 ms
83,788 KB
testcase_13 AC 206 ms
83,728 KB
testcase_14 AC 68 ms
70,948 KB
testcase_15 AC 67 ms
70,944 KB
testcase_16 AC 67 ms
71,280 KB
testcase_17 AC 68 ms
71,184 KB
testcase_18 AC 68 ms
71,160 KB
testcase_19 AC 68 ms
71,124 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