結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー alorie10alorie10
提出日時 2021-07-09 22:13:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 818 ms / 2,000 ms
コード長 715 bytes
コンパイル時間 1,493 ms
コンパイル使用メモリ 163,848 KB
実行使用メモリ 6,664 KB
最終ジャッジ日時 2023-09-14 09:26:07
合計ジャッジ時間 12,316 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,596 KB
testcase_01 AC 10 ms
6,492 KB
testcase_02 AC 808 ms
6,348 KB
testcase_03 AC 818 ms
6,596 KB
testcase_04 AC 818 ms
6,480 KB
testcase_05 AC 809 ms
6,348 KB
testcase_06 AC 812 ms
6,484 KB
testcase_07 AC 809 ms
6,488 KB
testcase_08 AC 800 ms
6,336 KB
testcase_09 AC 795 ms
6,664 KB
testcase_10 AC 796 ms
6,476 KB
testcase_11 AC 778 ms
6,556 KB
testcase_12 AC 762 ms
6,348 KB
testcase_13 AC 757 ms
6,532 KB
testcase_14 AC 9 ms
6,344 KB
testcase_15 AC 10 ms
6,544 KB
testcase_16 AC 9 ms
6,404 KB
testcase_17 AC 10 ms
6,400 KB
testcase_18 AC 10 ms
6,344 KB
testcase_19 AC 10 ms
6,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,MOD=1e9+7,a,b,ans,bik[400001],c;
ll f(ll x,ll y){
    if(y==0)return 1;
    if(y%2==0)return f(x,y/2)*f(x,y/2)%MOD;
    return x*f(x,y-1)%MOD;
}
ll comb(ll x, ll y){
    return bik[x]*f(bik[x-y],MOD-2)%MOD*f(bik[y],MOD-2)%MOD;
}
int main(void){
    cin>>n>>m;
    bik[0]=1;
    for(ll i=1;i<=400000;i++){
        bik[i]=bik[i-1]*i;
        bik[i]%=MOD;
    }
    //cout<<comb(n+m,m)<<endl;
    ans=comb(2*n,n)*2*n%MOD;
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        if(a==1)ans-=comb(b+c,c)*comb(2*n-b-c-1,n-c)%MOD;
        if(a==2)ans-=comb(b+c,c)*comb(2*n-b-c-1,n-b)%MOD;
        ans%=MOD;
    }
    cout<<(ans+MOD)%MOD<<endl;
}
0