結果
問題 | No.1596 Distance Sum in 2D Plane |
ユーザー |
![]() |
提出日時 | 2021-07-09 21:42:29 |
言語 | C++17 (gcc 11.2.0 + boost 1.78.0) |
結果 |
AC
|
実行時間 | 121 ms / 2,000 ms |
コード長 | 3,003 bytes |
コンパイル時間 | 1,892 ms |
使用メモリ | 12,948 KB |
最終ジャッジ日時 | 2023-02-01 22:41:13 |
合計ジャッジ時間 | 5,195 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 63 ms
12,848 KB |
testcase_01 | AC | 62 ms
12,768 KB |
testcase_02 | AC | 118 ms
12,824 KB |
testcase_03 | AC | 116 ms
12,896 KB |
testcase_04 | AC | 117 ms
12,892 KB |
testcase_05 | AC | 117 ms
12,908 KB |
testcase_06 | AC | 121 ms
12,772 KB |
testcase_07 | AC | 118 ms
12,872 KB |
testcase_08 | AC | 117 ms
12,840 KB |
testcase_09 | AC | 116 ms
12,844 KB |
testcase_10 | AC | 117 ms
12,812 KB |
testcase_11 | AC | 103 ms
12,772 KB |
testcase_12 | AC | 104 ms
12,876 KB |
testcase_13 | AC | 103 ms
12,840 KB |
testcase_14 | AC | 62 ms
12,888 KB |
testcase_15 | AC | 62 ms
12,892 KB |
testcase_16 | AC | 63 ms
12,772 KB |
testcase_17 | AC | 62 ms
12,948 KB |
testcase_18 | AC | 63 ms
12,876 KB |
testcase_19 | AC | 62 ms
12,820 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; template<class T> using vc = vector<T>; template<class T> using vvc = vector<vector<T>>; #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = (n)-1; i >= 0; i--) #define repe(i, l, r) for (ll i = (l); i < (r); i++) #define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--) #define repa(i,n) for (auto& i: n) template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;} template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;} struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);cerr<<fixed<<setprecision(15);}}init_; #ifdef DEBUG template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; } template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; } template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; } template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; } ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; } template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); } #endif const ll INF = 4e18; const ld EPS = 1e-11; const ld PI = acos(-1.0L); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; //--------------------------------------------------------------------------------// ll modpow(ll a, ll n, ll mod_) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod_; a = a * a % mod_; n >>= 1; } return res; } const ll MAX_SIZE = 400005; array<ll, MAX_SIZE> fac, inv, finv; struct finit{ finit(){ // combination init fac[0] = 1; for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % MOD; finv[MAX_SIZE - 1] = modpow(fac[MAX_SIZE - 1], MOD - 2, MOD); for(ll i = MAX_SIZE - 1; i > 0; i--) finv[i - 1] = finv[i] * i % MOD; //inv init repe(i, 1, MAX_SIZE) inv[i] = modpow(i, MOD - 2, MOD); } } finit_; ll perm(ll a, ll b) { return fac[a] * finv[a - b] % MOD; } ll comb(ll a, ll b) { return fac[a] * finv[b] % MOD * finv[a - b] % MOD; } int main() { ll N, M; cin >> N >> M; ll ans = comb(2 * N, N) * 2 * N % MOD; rep(i, M){ ll t, x, y; cin >> t >> x >> y; if(t == 1){ (ans -= comb(x + y, x) * comb(N - x - 1 + N - y, N - y)) %= MOD; }else{ (ans -= comb(x + y, x) * comb(N - x - 1 + N - y, N - y - 1)) %= MOD; } } cout << (ans + MOD) % MOD << endl; }