結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー tcltk
提出日時 2021-11-20 03:35:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 356 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 1,104 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 177,164 KB
最終ジャッジ日時 2025-01-02 10:47:16
合計ジャッジ時間 8,683 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """2 1
# 1 0 0
# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**10

MOD = 1000000007


fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

def comb(n, r):
    r = min(r, n - r)
    return (fact[n] * factinv[r] * factinv[n-r]) % MOD


N, M = map(int, input().split())
for i in range(2, 2*N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

ans = (comb(2*N, N) * 2*N) % MOD
for _ in range(M):
    t, x, y = map(int, input().split())
    if t == 1:
        x1, y1 = x+1, y
    else:
        x1, y1 = x, y+1
    
    v = comb(x+y, x) * comb((N-x1)+(N-y1), N-x1)
    ans = (ans - v) % MOD

print(ans)
0