結果

問題 No.1596 Distance Sum in 2D Plane
コンテスト
ユーザー cologne
提出日時 2026-01-02 15:54:14
言語 PyPy3
(7.3.17)
結果
TLE  
実行時間 -
コード長 1,022 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 334 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 82,636 KB
最終ジャッジ日時 2026-01-02 15:54:20
合計ジャッジ時間 5,517 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 2 TLE * 1 -- * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
from typing import List, Tuple


def int1(x: str, /): return int(x) - 1


def input(): return sys.stdin.readline().rstrip('\n')


def dbg(*args, **kwargs):
    print(*(repr(arg) for arg in args), *(f'{k}: {repr(v)}' for k, v in kwargs.items()), sep='; ', file=sys.stderr)


M = 10 ** 9 + 7


def fact(x):
    s = 1
    for i in range(1, x + 1):
        s *= i
        s %= M
    return s


def main():
    n, m = map(int, input().split())
    tot = 2 * n * fact(2 * n) * pow(fact(n), -2, M) % M
    for _ in range(m):
        t, x, y = map(int, input().split())
        tot -= fact(x + y) * pow(fact(x) * fact(y), -1, M) * fact((2 * n - 1) - (x + y)) * \
               pow(fact(n - (x + (0 if t == 2 else 1))) * fact(n - (y + (0 if t == 1 else 1))), -1, M)
        tot %= M
    return tot


def _start():
    ret = main()

    if ret is not None:
        if isinstance(ret, List) or isinstance(ret, Tuple):
            print(*ret)
        else:
            print(ret)


if __name__ == '__main__':
    _start()
0