結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー wolleywolley
提出日時 2021-07-10 10:30:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 709 ms / 2,000 ms
コード長 1,455 bytes
コンパイル時間 3,585 ms
コンパイル使用メモリ 226,844 KB
実行使用メモリ 120,800 KB
最終ジャッジ日時 2023-09-14 18:47:06
合計ジャッジ時間 17,817 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 510 ms
120,536 KB
testcase_01 AC 506 ms
120,536 KB
testcase_02 AC 654 ms
120,512 KB
testcase_03 AC 665 ms
120,652 KB
testcase_04 AC 675 ms
120,596 KB
testcase_05 AC 672 ms
120,776 KB
testcase_06 AC 641 ms
120,628 KB
testcase_07 AC 709 ms
120,568 KB
testcase_08 AC 641 ms
120,592 KB
testcase_09 AC 654 ms
120,800 KB
testcase_10 AC 645 ms
120,796 KB
testcase_11 AC 664 ms
120,628 KB
testcase_12 AC 652 ms
120,568 KB
testcase_13 AC 658 ms
120,564 KB
testcase_14 AC 521 ms
120,628 KB
testcase_15 AC 525 ms
120,520 KB
testcase_16 AC 505 ms
120,652 KB
testcase_17 AC 509 ms
120,572 KB
testcase_18 AC 501 ms
120,500 KB
testcase_19 AC 512 ms
120,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SIZE(x) ll(x.size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
typedef pair<int, int> P;
const int MAX = 10000000;
mint fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i;
        inv[i] = MOD - inv[MOD%i] * (MOD / i);
        finv[i] = finv[i - 1] * inv[i];
    }
}

// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
int main()
{
    COMinit();
    int N, M;
    cin >> N >> M;

    mint res = COM(2 * N, N);
    res *= 2 * N;

    rep(i, M) {
        int t, x, y;
        cin >> t >> x >> y;
        mint from = COM(x + y, x);
        if (t == 1) x++;
        else y++;
        mint to = COM(N - x + N - y, N - x);
        res -= from * to;
    }

    cout << res.val() << endl;
    return 0;
}
0