結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー |
![]() |
提出日時 | 2021-07-09 21:51:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 158 ms / 2,000 ms |
コード長 | 1,043 bytes |
コンパイル時間 | 4,510 ms |
コンパイル使用メモリ | 252,932 KB |
最終ジャッジ日時 | 2025-01-22 21:32:29 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; typedef long long ll; typedef pair<ll,ll> P; typedef modint1000000007 mint; #define rep(i,a,b) for(ll i=a;i<b;i++) #define rrep(i,a,b) for(ll i=a;i>=b;i--) const ll inf=1e18; struct combination { vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } } comb(500005); ll n,m; ll t,x,y; mint ans; int main(void){ cin.tie(0); ios::sync_with_stdio(0); cin>>n>>m; ans=2*mint(n)*comb(2*n,n); rep(i,0,m){ cin>>t>>x>>y; if(t==1){ ans-=comb(x+y,x)*comb(n*2-(x+y)-1,n-y); }else{ ans-=comb(x+y,x)*comb(n*2-(x+y)-1,n-x); } } cout<<ans.val()<<endl; }