結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー nrvftnrvft
提出日時 2021-07-09 21:42:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 3,003 bytes
コンパイル時間 2,010 ms
コンパイル使用メモリ 199,236 KB
実行使用メモリ 12,988 KB
最終ジャッジ日時 2023-09-14 08:15:12
合計ジャッジ時間 5,526 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
12,764 KB
testcase_01 AC 75 ms
12,728 KB
testcase_02 AC 137 ms
12,716 KB
testcase_03 AC 137 ms
12,800 KB
testcase_04 AC 135 ms
12,784 KB
testcase_05 AC 136 ms
12,728 KB
testcase_06 AC 136 ms
12,776 KB
testcase_07 AC 136 ms
12,804 KB
testcase_08 AC 137 ms
12,756 KB
testcase_09 AC 135 ms
12,724 KB
testcase_10 AC 136 ms
12,764 KB
testcase_11 AC 121 ms
12,804 KB
testcase_12 AC 121 ms
12,844 KB
testcase_13 AC 121 ms
12,780 KB
testcase_14 AC 74 ms
12,920 KB
testcase_15 AC 75 ms
12,732 KB
testcase_16 AC 74 ms
12,728 KB
testcase_17 AC 74 ms
12,784 KB
testcase_18 AC 75 ms
12,708 KB
testcase_19 AC 75 ms
12,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0