結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー shiomusubi496shiomusubi496
提出日時 2021-07-09 21:42:18
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 645 bytes
コンパイル時間 1,807 ms
使用メモリ 11,720 KB
最終ジャッジ日時 2023-02-01 22:40:54
合計ジャッジ時間 6,216 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 11 ms
11,672 KB
testcase_01 AC 12 ms
11,568 KB
testcase_02 AC 243 ms
11,568 KB
testcase_03 AC 242 ms
11,640 KB
testcase_04 AC 242 ms
11,692 KB
testcase_05 AC 239 ms
11,720 KB
testcase_06 AC 247 ms
11,644 KB
testcase_07 AC 241 ms
11,636 KB
testcase_08 AC 246 ms
11,620 KB
testcase_09 AC 238 ms
11,644 KB
testcase_10 AC 241 ms
11,568 KB
testcase_11 AC 224 ms
11,568 KB
testcase_12 AC 223 ms
11,624 KB
testcase_13 AC 221 ms
11,676 KB
testcase_14 AC 11 ms
11,576 KB
testcase_15 AC 11 ms
11,632 KB
testcase_16 AC 11 ms
11,720 KB
testcase_17 AC 11 ms
11,692 KB
testcase_18 AC 11 ms
11,572 KB
testcase_19 AC 11 ms
11,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1000000007;
int fact[1<<20];
int mod_pow(int a,int b){
    if(!b)return 1;
    if(b&1)return mod_pow(a,b-1)*a%mod;
    return mod_pow(a*a%mod,b/2);
}
int com(int n,int r){
    return fact[n]*mod_pow(fact[n-r]*fact[r]%mod,mod-2)%mod;
}
signed main(){
    fact[0]=1;
    for(int i=1;i<(1<<20);i++)fact[i]=fact[i-1]*i%mod;
    int N,M; cin>>N>>M;
    int ans=com(2*N,N)*(2*N)%mod;
    for(int i=0;i<M;i++){
        int t,x,y; cin>>t>>x>>y;
        int nx=N-x-(t==1),ny=N-y-(t==2);
        (ans+=mod-com(x+y,x)*com(nx+ny,nx)%mod)%=mod;
    }
    cout<<ans<<endl;
}
0