結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー shiomusubi496shiomusubi496
提出日時 2021-07-09 21:42:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 645 bytes
コンパイル時間 1,990 ms
コンパイル使用メモリ 198,296 KB
実行使用メモリ 11,856 KB
最終ジャッジ日時 2023-09-14 08:14:58
合計ジャッジ時間 6,254 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
11,516 KB
testcase_01 AC 10 ms
11,532 KB
testcase_02 AC 249 ms
11,528 KB
testcase_03 AC 253 ms
11,540 KB
testcase_04 AC 249 ms
11,512 KB
testcase_05 AC 251 ms
11,596 KB
testcase_06 AC 255 ms
11,840 KB
testcase_07 AC 256 ms
11,580 KB
testcase_08 AC 256 ms
11,640 KB
testcase_09 AC 252 ms
11,540 KB
testcase_10 AC 255 ms
11,572 KB
testcase_11 AC 226 ms
11,544 KB
testcase_12 AC 226 ms
11,524 KB
testcase_13 AC 225 ms
11,540 KB
testcase_14 AC 10 ms
11,856 KB
testcase_15 AC 10 ms
11,584 KB
testcase_16 AC 10 ms
11,580 KB
testcase_17 AC 10 ms
11,540 KB
testcase_18 AC 10 ms
11,716 KB
testcase_19 AC 9 ms
11,536 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