結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー rianoriano
提出日時 2021-07-09 22:01:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 307 ms / 2,000 ms
コード長 1,314 bytes
コンパイル時間 1,358 ms
コンパイル使用メモリ 168,120 KB
実行使用メモリ 9,612 KB
最終ジャッジ日時 2023-09-14 09:03:52
合計ジャッジ時間 6,596 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
9,312 KB
testcase_01 AC 139 ms
9,256 KB
testcase_02 AC 299 ms
9,304 KB
testcase_03 AC 305 ms
9,260 KB
testcase_04 AC 299 ms
9,612 KB
testcase_05 AC 300 ms
9,260 KB
testcase_06 AC 302 ms
9,312 KB
testcase_07 AC 305 ms
9,364 KB
testcase_08 AC 307 ms
9,368 KB
testcase_09 AC 307 ms
9,260 KB
testcase_10 AC 306 ms
9,308 KB
testcase_11 AC 278 ms
9,248 KB
testcase_12 AC 282 ms
9,312 KB
testcase_13 AC 280 ms
9,244 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0