結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー | yuji9511 |
提出日時 | 2021-07-09 22:26:11 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 88 ms / 2,000 ms |
コード長 | 2,377 bytes |
コンパイル時間 | 2,250 ms |
コンパイル使用メモリ | 206,076 KB |
実行使用メモリ | 17,280 KB |
最終ジャッジ日時 | 2024-07-01 17:04:31 |
合計ジャッジ時間 | 4,338 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
12,544 KB |
testcase_01 | AC | 18 ms
12,544 KB |
testcase_02 | AC | 76 ms
17,280 KB |
testcase_03 | AC | 75 ms
17,152 KB |
testcase_04 | AC | 76 ms
17,152 KB |
testcase_05 | AC | 88 ms
17,152 KB |
testcase_06 | AC | 75 ms
17,152 KB |
testcase_07 | AC | 75 ms
17,152 KB |
testcase_08 | AC | 74 ms
17,152 KB |
testcase_09 | AC | 75 ms
17,280 KB |
testcase_10 | AC | 75 ms
17,152 KB |
testcase_11 | AC | 66 ms
17,152 KB |
testcase_12 | AC | 65 ms
17,152 KB |
testcase_13 | AC | 66 ms
17,152 KB |
testcase_14 | AC | 18 ms
12,544 KB |
testcase_15 | AC | 18 ms
12,544 KB |
testcase_16 | AC | 18 ms
12,544 KB |
testcase_17 | AC | 18 ms
12,672 KB |
testcase_18 | AC | 17 ms
12,672 KB |
testcase_19 | AC | 17 ms
12,544 KB |
ソースコード
/*** author: yuji9511 ***/ #include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; using lpair = pair<ll, ll>; using vll = vector<ll>; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) ostream& operator<<(ostream& os, lpair& h){ os << "(" << h.first << ", " << h.second << ")"; return os;} #define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];}; void print() {} template <class H,class... T> void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);} template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } struct Combination{ private: ll N; public: vll fac, facinv, inv; Combination(ll n){ N = n; fac.resize(N+1); facinv.resize(N+1); inv.resize(N+1); fac[0] = fac[1] = 1; facinv[0] = facinv[1] = 1; inv[1] = 1; rep(i,2,N+1){ fac[i] = fac[i-1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; facinv[i] = facinv[i-1] * inv[i] % MOD; } } ll power(ll x, ll n, ll m = MOD){ if(n == 0) return 1LL; ll res = power(x * x % m, n/2, m); if(n % 2 == 1) (res *= x) %= m; return res; } ll nck(ll n, ll k){ if(n == 0) return 1LL; if(k == 0 || n == k) return 1LL; if(n < k) return 0LL; return fac[n] * facinv[k] % MOD * facinv[n-k] % MOD; } ll npk(ll n, ll k){ if(k == 0) return 1LL; if(n < k) return 0LL; return fac[n] * facinv[n-k] % MOD; } }; void solve(){ ll N,M; cin >> N >> M; vll t(M), x(M), y(M); rep(i,0,M) cin >> t[i] >> x[i] >> y[i]; Combination cb(400010); ll ans = cb.nck(2*N, N) * 2 * N % MOD; rep(i,0,M){ if(t[i] == 1){ ans -= cb.nck(x[i]+y[i], x[i]) * cb.nck(2*N-x[i]-y[i]-1, N-y[i]) % MOD; ans = (ans + 2*MOD) % MOD; }else{ ans -= cb.nck(x[i]+y[i], x[i]) * cb.nck(2*N-x[i]-y[i]-1, N-x[i]) % MOD; ans = (ans + 2*MOD) % MOD; } } print(ans); } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }