結果
| 問題 | No.1596 Distance Sum in 2D Plane | 
| コンテスト | |
| ユーザー |  riano | 
| 提出日時 | 2021-07-09 22:01:45 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 342 ms / 2,000 ms | 
| コード長 | 1,314 bytes | 
| コンパイル時間 | 1,569 ms | 
| コンパイル使用メモリ | 169,684 KB | 
| 実行使用メモリ | 9,580 KB | 
| 最終ジャッジ日時 | 2024-07-01 16:24:11 | 
| 合計ジャッジ時間 | 7,150 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Pr pair<ll,ll>
#define Tp tuple<ll,ll,ll>
using Graph = vector<vector<int>>;
ll mod = 1000000007;
//mod逆元
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
 
 
//Combination2
//10^6くらいまで
//modはグローバルに定義しておく
vector<ll> fact;
vector<ll> invf;
ll comb(ll n,ll k){
    if(n<0||k<0||k>n) return 0LL;
    else{
        ll a = fact[n]*invf[k]%mod;
        a = a*invf[n-k]%mod;
        return a;
    }
}
int main() {
    ll N,M; cin >> N >> M;
    //main関数内に以下ペースト
    //N:max
    fact.assign(2*N+1,1LL);
    invf.assign(2*N+1,1LL);
    rep(i,2*N) fact[i+1] = fact[i]*(i+1)%mod;
    rep(i,2*N+1) invf[i] = modinv(fact[i],mod);
    ll ans = 2*N*comb(2*N,N)%mod;
    //cout << ans << endl;
    rep(i,M){
        ll t,x,y; cin >> t >> x >> y;
        ll x1 = x,y1 = y;
        if(t==1){
            x1++;
        }
        else y1++;
        ans += (mod-comb(x+y,x)*comb(2*N-x1-y1,N-x1)%mod);
        ans %= mod;
    }
    cout << ans << endl;
}
            
            
            
        