結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー tktk_snsntktk_snsn
提出日時 2021-07-09 21:55:18
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,559 bytes
コンパイル時間 859 ms
使用メモリ 87,844 KB
最終ジャッジ日時 2023-02-01 23:15:18
合計ジャッジ時間 4,935 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 108 ms
86,540 KB
testcase_01 AC 109 ms
86,972 KB
testcase_02 AC 198 ms
87,844 KB
testcase_03 AC 202 ms
87,680 KB
testcase_04 AC 194 ms
87,820 KB
testcase_05 AC 193 ms
87,812 KB
testcase_06 AC 197 ms
87,576 KB
testcase_07 AC 194 ms
87,680 KB
testcase_08 AC 193 ms
87,676 KB
testcase_09 AC 194 ms
87,532 KB
testcase_10 AC 196 ms
87,700 KB
testcase_11 AC 179 ms
87,712 KB
testcase_12 AC 176 ms
87,696 KB
testcase_13 AC 175 ms
87,672 KB
testcase_14 AC 82 ms
75,648 KB
testcase_15 AC 82 ms
75,548 KB
testcase_16 AC 86 ms
75,656 KB
testcase_17 AC 83 ms
75,500 KB
testcase_18 AC 82 ms
75,564 KB
testcase_19 AC 83 ms
75,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7


class Combination:
    """
    SIZEが10**6程度以下の二項係数を何回も呼び出したいときに使う
    使い方:
    comb = Combination(SIZE, MOD)
    comb(10, 3) => 120
    """

    def __init__(self, N, MOD=10 ** 9 + 7):
        self.MOD = MOD
        self.__make_factorial_list(N)

    def __call__(self, n, k):
        if k < 0 or k > n:
            return 0
        res = self.fact[n] * self.inv[k] % self.MOD
        res = res * self.inv[n - k] % self.MOD
        return res

    def nPk(self, n, k):
        if k < 0 or k > n:
            return 0
        return self.fact[n] * self.inv[n - k] % self.MOD

    def nHk(self, n, k):
        if k == 0:
            return 1
        return self.__call__(n + k - 1, k)

    def __make_factorial_list(self, N):
        self.fact = [1] * (N + 1)
        self.inv = [1] * (N + 1)
        MOD = self.MOD
        for i in range(1, N + 1):
            self.fact[i] = (self.fact[i - 1] * i) % MOD
        self.inv[N] = pow(self.fact[N], MOD - 2, MOD)
        for i in range(N, 0, -1):
            self.inv[i - 1] = (self.inv[i] * i) % MOD
        return


N, M = map(int, input().split())
comb = Combination(N+N+100, mod)
ans = 2 * N * comb(2 * N, N) % mod

for _ in range(M):
    T, X, Y = map(int, input().split())
    a_to_m = comb(X + Y, X)
    if T == 1:
        X += 1
    else:
        Y += 1
    m_to_b = comb(2 * N - X - Y, N - X)

    ans -= a_to_m * m_to_b % mod
    ans %= mod

print(ans)
0