結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー CJ314CJ314
提出日時 2021-07-09 22:34:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 1,498 bytes
コンパイル時間 4,345 ms
コンパイル使用メモリ 262,460 KB
実行使用メモリ 11,076 KB
最終ジャッジ日時 2023-09-14 09:51:42
合計ジャッジ時間 9,224 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
10,780 KB
testcase_01 AC 137 ms
10,848 KB
testcase_02 AC 200 ms
10,828 KB
testcase_03 AC 199 ms
10,936 KB
testcase_04 AC 199 ms
10,916 KB
testcase_05 AC 199 ms
10,832 KB
testcase_06 AC 200 ms
10,904 KB
testcase_07 AC 198 ms
10,832 KB
testcase_08 AC 197 ms
10,852 KB
testcase_09 AC 197 ms
10,900 KB
testcase_10 AC 197 ms
10,836 KB
testcase_11 AC 186 ms
10,948 KB
testcase_12 AC 186 ms
10,836 KB
testcase_13 AC 186 ms
10,760 KB
testcase_14 AC 138 ms
10,972 KB
testcase_15 AC 137 ms
10,760 KB
testcase_16 AC 137 ms
10,808 KB
testcase_17 AC 138 ms
11,076 KB
testcase_18 AC 138 ms
11,020 KB
testcase_19 AC 137 ms
10,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using pll = std::pair<long long, long long>;
#define rep(i, n) for (long long i = 0LL; i < (long long)(n); i++)
#define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++)
#define repr(i, n) for (long long i = (long long)(n) - 1; i >= 0LL; i--)
#define repr2(i, n, s) for (long long i = (long long)(n) - 1; i >= (long long)(s); i--)
#define nCr(n, r) ((n) >= (r) ? fac.at(n) * inv_fac.at(r) * inv_fac.at((n) - (r)) : 0)
template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 2e18;

using mint = modint1000000007;

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    vector<mint> fac(1'000'000 + 1, 1), inv_fac(1'000'000 + 1, 1);
    rep2(i_, 2, 1'000'000 + 1) {
        fac[i_] = i_ * fac[i_ - 1];
        inv_fac[i_] = fac[i_].inv();
    }

    ll N, M;
    cin >> N >> M;
    mint ans = 2 * N * nCr(2 * N, N);
    rep(i, M) {
        ll t, x, y;
        cin >> t >> x >> y;
        if (t == 1) {
            ans -= nCr(x + y, x) * nCr(2 * N - (x + y + 1), N - y);
        } else {
            ans -= nCr(x + y, x) * nCr(2 * N - (x + y + 1), N - x);
        }
    }
    cout << ans.val() << "\n";
}
0