結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー terasaterasa
提出日時 2022-11-03 14:24:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 421 ms / 2,000 ms
コード長 1,867 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 130,644 KB
最終ジャッジ日時 2023-09-24 23:42:53
合計ジャッジ時間 9,022 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 225 ms
102,088 KB
testcase_01 AC 227 ms
102,084 KB
testcase_02 AC 421 ms
130,396 KB
testcase_03 AC 405 ms
130,644 KB
testcase_04 AC 416 ms
130,412 KB
testcase_05 AC 406 ms
130,332 KB
testcase_06 AC 404 ms
130,184 KB
testcase_07 AC 409 ms
130,324 KB
testcase_08 AC 402 ms
130,172 KB
testcase_09 AC 392 ms
130,224 KB
testcase_10 AC 379 ms
130,264 KB
testcase_11 AC 374 ms
130,396 KB
testcase_12 AC 385 ms
130,488 KB
testcase_13 AC 389 ms
130,336 KB
testcase_14 AC 109 ms
72,348 KB
testcase_15 AC 108 ms
72,516 KB
testcase_16 AC 108 ms
72,660 KB
testcase_17 AC 110 ms
72,376 KB
testcase_18 AC 108 ms
72,512 KB
testcase_19 AC 110 ms
72,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import itertools
import heapq
import bisect
from collections import deque, defaultdict
from functools import lru_cache, cmp_to_key

input = sys.stdin.readline

# for AtCoder Easy test
if __file__ != 'prog.py':
    sys.setrecursionlimit(10 ** 6)


def readints(): return map(int, input().split())
def readlist(): return list(readints())
def readstr(): return input().rstrip()


class Combination:
    def __init__(self, N, mod):
        self.N = N
        self.mod = mod
        self.f = [None] * (N + 1)
        self.finv = [None] * (N + 1)
        self.inv = [None] * (N + 1)

        self.f[0] = 1
        self.f[1] = 1
        self.finv[0] = 1
        self.finv[1] = 1
        self.inv[1] = 1
        for i in range(2, N + 1):
            self.f[i] = self.f[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 P(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return self.f[n] * self.finv[n - k] % self.mod

    def C(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return self.f[n] * (self.finv[k] * self.finv[n - k] % self.mod) % self.mod

    # 重複組合せ
    # n種類のものからk個選ぶ
    def H(self, n, k):
        if n == 0 and k == 0:
            return 1
        return self.C(k + n - 1, k)


N, M = readints()
mod = 10 ** 9 + 7
comb = Combination(2 * N, mod)
P = [tuple(readints()) for _ in range(M)]

ans = comb.C(2 * N, N) * (2 * N) % mod
for t, x, y in P:
    if t == 1:
        ans -= comb.C(x + y, x) * comb.C(2 * N - (x + y + 1), N - (x + 1)) % mod
    else:
        ans -= comb.C(x + y, x) * comb.C(2 * N - (x + y + 1),  N - (y + 1)) % mod
    ans %= mod
print(ans)
0