結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー kobakoba_issakobakoba_issa
提出日時 2021-07-09 22:46:11
言語 C++17(clang Beta)
(clang 13.0.0 + boost 1.78.0)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 1,507 bytes
コンパイル時間 1,330 ms
使用メモリ 26,848 KB
最終ジャッジ日時 2023-02-02 00:49:24
合計ジャッジ時間 4,831 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 23 ms
26,820 KB
testcase_01 AC 22 ms
26,748 KB
testcase_02 AC 166 ms
26,808 KB
testcase_03 AC 166 ms
26,812 KB
testcase_04 AC 173 ms
26,724 KB
testcase_05 AC 169 ms
26,756 KB
testcase_06 AC 164 ms
26,748 KB
testcase_07 AC 166 ms
26,748 KB
testcase_08 AC 167 ms
26,840 KB
testcase_09 AC 167 ms
26,748 KB
testcase_10 AC 163 ms
26,828 KB
testcase_11 AC 151 ms
26,816 KB
testcase_12 AC 151 ms
26,812 KB
testcase_13 AC 154 ms
26,756 KB
testcase_14 AC 22 ms
26,848 KB
testcase_15 AC 23 ms
26,820 KB
testcase_16 AC 22 ms
26,816 KB
testcase_17 AC 21 ms
26,808 KB
testcase_18 AC 20 ms
26,728 KB
testcase_19 AC 20 ms
26,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = (1<<30)-1;
const ll LINF = (1LL<<60)-1;

#define rep(i, n) for (int i = 0; i < n; i++)
#define sz(a) (int)(a.size())

template<class T> 
bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;}

template<class T> 
bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;}

#define MAX (ll)1e6+1    //nCrのnの最大値+1

ll fac[MAX], inv[MAX], finv[MAX];

void COMinit(ll mod) {
    fac[0] = 1, finv[0] = 1;
    fac[1] = 1, inv[1] = 1, finv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - (inv[mod % i] * (mod/i) % mod) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll COM(ll n, ll k, ll mod) {
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * finv[k] % mod * finv[n-k] % mod;
}


//コーナーケースに気をつけろ!
int main() {
    int n, m;   cin >> n >> m;
    ll mod = 1e9+7;
    COMinit(mod);
    ll ans = 2*n * COM(2*n, n, mod) % mod;
    rep(i, m) {
        int x, y, t;    cin >> t >> x >> y;
        if (t == 1) {
            ans = (ans + mod - COM(x+y, x, mod) * COM(2*n-1-x-y, n-y, mod) % mod) % mod;
        }
        else {
            ans = (ans + mod - COM(x+y, x, mod) * COM(2*n-1-x-y, n-x, mod) % mod) % mod;
        }
    }
    cout << ans << endl;
    return 0;   
}

//小数点精度
//cout << fixed << std::setprecision(15) << y << endl;
0