結果
問題 |
No.1596 Distance Sum in 2D Plane
|
ユーザー |
![]() |
提出日時 | 2021-07-09 21:53:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 930 bytes |
コンパイル時間 | 1,774 ms |
コンパイル使用メモリ | 198,404 KB |
最終ジャッジ日時 | 2025-01-22 21:35:50 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 TLE * 12 |
ソースコード
#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){ vector<int> cache{1}; while(cache.size()<=n) cache.push_back(1ll*cache.back()*cache.size()%P); return cache[n]; } int ifac(int n){ 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; }