結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー detteiuu
提出日時 2024-09-23 17:36:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 568 ms / 2,000 ms
コード長 847 bytes
コンパイル時間 5,601 ms
コンパイル使用メモリ 82,224 KB
実行使用メモリ 147,040 KB
最終ジャッジ日時 2024-09-23 17:50:42
合計ジャッジ時間 22,202 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

class CP:
    def __init__(self, N):
        self.fact = [1]
        self.fact_inv = [1]
        for i in range(1, N+1):
            self.fact.append((self.fact[-1]*i)%MOD)
            self.fact_inv.append(pow(self.fact[-1], -1, MOD))
    def C(self, N, K):
        if N >= K:
            return self.fact[N]*self.fact_inv[K]%MOD*self.fact_inv[N-K]%MOD
        else:
            return 0
    def P(self, N, K):
        if N >= K:
            return self.fact[N]*self.fact_inv[N-K]%MOD
        else:
            return 0

N, M = map(int, input().split())
free = [list(map(int, input().split())) for _ in range(M)]

MOD = 10**9+7
cp = CP(10**5*4)
ans = cp.C(N*2, N)*(N*2)%MOD

for t, x, y in free:
    if t == 1:
        nx, ny = N-x-1, N-y
    else:
        nx, ny = N-x, N-y-1
    ans -= cp.C(x+y, x)*cp.C(nx+ny, nx)%MOD
    ans %= MOD

print(ans)
0