結果
| 問題 |
No.1596 Distance Sum in 2D Plane
|
| コンテスト | |
| ユーザー |
cai_lw
|
| 提出日時 | 2021-07-09 23:19:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 287 ms / 2,000 ms |
| コード長 | 944 bytes |
| コンパイル時間 | 2,664 ms |
| コンパイル使用メモリ | 198,020 KB |
| 最終ジャッジ日時 | 2025-01-22 22:41:17 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P=1000000007;
int mpow(int x,int n){
if(n==1)return x;
ll half=mpow(x,n/2),ret=half*half%P;
if(n%2)ret=ret*x%P;
return ret;
}
int inv(int x){
return mpow(x,P-2);
}
int fac(int n){
static vector<int> cache{1};
while(cache.size()<=n)
cache.push_back(1ll*cache.back()*cache.size()%P);
return cache[n];
}
int ifac(int n){
static vector<int> cache{1};
while(cache.size()<=n)
cache.push_back(1ll*cache.back()*inv(cache.size())%P);
return cache[n];
}
int binom(int n,int m){
return 1ll*fac(n)*ifac(m)%P*ifac(n-m)%P;
}
int main(){
int n,m;
cin>>n>>m;
int ans=0;
for(int i=0;i<m;i++){
int t,x0,y0;
cin>>t>>x0>>y0;
int x1=x0,y1=y0;
if(t==1)x1++;
else y1++;
ans+=1ll*binom(x0+y0,x0)*binom(n*2-x1-y1,n-x1)%P;
if(ans>=P)ans-=P;
}
ans=1ll*binom(n*2,n)*n*2%P-ans;
if(ans<0)ans+=P;
cout<<ans<<endl;
}
cai_lw