結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー merom686merom686
提出日時 2021-07-09 21:57:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,024 bytes
コンパイル時間 2,078 ms
コンパイル使用メモリ 203,476 KB
実行使用メモリ 6,388 KB
最終ジャッジ日時 2023-09-14 08:54:32
合計ジャッジ時間 4,001 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,248 KB
testcase_01 AC 7 ms
6,156 KB
testcase_02 AC 62 ms
6,196 KB
testcase_03 AC 61 ms
6,212 KB
testcase_04 AC 62 ms
6,148 KB
testcase_05 AC 60 ms
6,136 KB
testcase_06 AC 61 ms
6,196 KB
testcase_07 AC 60 ms
6,260 KB
testcase_08 AC 61 ms
6,388 KB
testcase_09 AC 59 ms
6,208 KB
testcase_10 AC 60 ms
6,196 KB
testcase_11 AC 52 ms
6,216 KB
testcase_12 AC 51 ms
6,244 KB
testcase_13 AC 52 ms
6,364 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using mint = atcoder::modint1000000007;
using namespace std;
using ll = long long;

vector<mint> f0, f1;
void init(int n) {
    f0.resize(n + 1);
    f0[0] = 1;
    for (int i = 1; i <= n; i++) {
        f0[i] = f0[i - 1] * i;
    }
    f1.resize(n + 1);
    f1[n] = f0[n].inv();
    for (int i = n; i > 0; i--) {
        f1[i - 1] = f1[i] * i;
    }
}
mint fact(int k) {
    return f0[k];
}
mint comb(int n, int k) {
    if (n < k || k < 0) return 0;
    return f0[n] * f1[k] * f1[n - k];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    init(n * 2);

    mint r = comb(n * 2, n) * (n * 2);
    for (int i = 0; i < m; i++) {
        int t, x, y;
        cin >> t >> x >> y;

        if (t == 1) {
            r -= comb(x + y, y) * comb(n - (x + 1) + n - y, n - y);
        } else {
            r -= comb(x + y, y) * comb(n - x + n - (y + 1), n - (y + 1));
        }
    }
    cout << r.val() << endl;

    return 0;
}
0