結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー | 👑 Nachia |
提出日時 | 2021-07-09 22:00:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 1,065 bytes |
コンパイル時間 | 6,870 ms |
コンパイル使用メモリ | 154,364 KB |
最終ジャッジ日時 | 2025-01-22 21:45:16 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <atcoder/all> #include <iostream> #include <vector> #include <algorithm> #include <set> using namespace atcoder; using namespace std; using ll = long long; using ull = unsigned long long; const ull MOD = 1000000007; using mll = static_modint<1000000007>; #define rep(i,n) for(int i=0; i<(n); i++) vector<mll> F,I,iF; void initComb(int Z){ F.assign(Z+1,1); for(int i=1; i<=Z; i++) F[i] = F[i-1] * i; I.assign(Z+1,1); for(int i=2; i<=Z; i++) I[i] = -(I[MOD%i] * (MOD / i)); iF.assign(Z+1,1); for(int i=1; i<=Z; i++) iF[i] = iF[i-1] * I[i]; } mll Comb(int n,int r){ return F[n] * iF[r] * iF[n-r]; } int main(){ int N,M; cin >> N >> M; initComb(N+N); mll ans = Comb(N+N,N) * N * 2; rep(i,M){ int t,x,y; cin >> t >> x >> y; mll d = 1; d *= Comb(x+y,x); if(t == 1) d *= Comb(N-x-1+N-y,N-y); if(t == 2) d *= Comb(N-x+N-y-1,N-x); ans -= d; } cout << ans.val() << endl; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_inst;