結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー bbge_kyoprobbge_kyopro
提出日時 2021-07-09 21:58:19
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 335 ms / 2,000 ms
コード長 1,386 bytes
コンパイル時間 1,839 ms
使用メモリ 18,636 KB
最終ジャッジ日時 2023-02-01 23:20:46
合計ジャッジ時間 9,802 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 281 ms
18,432 KB
testcase_01 AC 281 ms
18,584 KB
testcase_02 AC 335 ms
18,436 KB
testcase_03 AC 332 ms
18,552 KB
testcase_04 AC 332 ms
18,636 KB
testcase_05 AC 331 ms
18,556 KB
testcase_06 AC 331 ms
18,552 KB
testcase_07 AC 331 ms
18,444 KB
testcase_08 AC 331 ms
18,440 KB
testcase_09 AC 332 ms
18,508 KB
testcase_10 AC 332 ms
18,436 KB
testcase_11 AC 323 ms
18,444 KB
testcase_12 AC 321 ms
18,560 KB
testcase_13 AC 322 ms
18,508 KB
testcase_14 AC 281 ms
18,564 KB
testcase_15 AC 281 ms
18,552 KB
testcase_16 AC 281 ms
18,472 KB
testcase_17 AC 282 ms
18,556 KB
testcase_18 AC 281 ms
18,480 KB
testcase_19 AC 281 ms
18,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

#include <atcoder/modint>
using mint = atcoder::modint1000000007;
#define MOD_UTILS_NMAX 2000100

struct mod_utils {
    // data
    std::vector<mint> _fac, _inv;
    // construct & initialize
    mod_utils() { 
        _fac.resize(MOD_UTILS_NMAX);
        _inv.resize(MOD_UTILS_NMAX);
        _fac[0] = 1; _fac[1] = 1;
        _inv[0] = 1; _inv[1] = 1;
        for(int i = 2; i < MOD_UTILS_NMAX; i++) {
            _fac[i] = _fac[i-1] * mint(i);
            _inv[i] = _inv[i-1] * mint(i).inv();
        }
    }
} _mod_utils;

// functions
mint fac(int i) { return _mod_utils._fac[i]; }
mint inv_fac(int i) { return _mod_utils._inv[i]; }
mint nck(int n, int k) { 
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    if(k == 0 || k == n) return 1;
    return _mod_utils._fac[n] * _mod_utils._inv[k] * _mod_utils._inv[n-k];
}

void solve() {
    ll n, m;
    cin >> n >> m;
    mint ans = nck(2*n, n) * 2 * n;
    rep(i, 0, m) {
        ll t, x, y;
        cin >> t >> x >> y;
        if(t == 1) ans -= nck(x+y, x) * nck(2*n-1-x-y, n-y);
        else ans -= nck(x+y, x) * nck(2*n-1-x-y, n-x);
    }
    cout << ans.val() << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
0