結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー kobakoba_issakobakoba_issa
提出日時 2021-07-09 22:46:11
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 1,507 bytes
コンパイル時間 4,490 ms
コンパイル使用メモリ 131,992 KB
実行使用メモリ 26,936 KB
最終ジャッジ日時 2023-09-14 10:25:09
合計ジャッジ時間 6,094 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
26,836 KB
testcase_01 AC 26 ms
26,900 KB
testcase_02 AC 199 ms
26,888 KB
testcase_03 AC 201 ms
26,928 KB
testcase_04 AC 204 ms
26,932 KB
testcase_05 AC 198 ms
26,892 KB
testcase_06 AC 200 ms
26,872 KB
testcase_07 AC 198 ms
26,860 KB
testcase_08 AC 200 ms
26,872 KB
testcase_09 AC 197 ms
26,920 KB
testcase_10 AC 201 ms
26,924 KB
testcase_11 AC 169 ms
26,900 KB
testcase_12 AC 171 ms
26,904 KB
testcase_13 AC 171 ms
26,836 KB
testcase_14 AC 27 ms
26,840 KB
testcase_15 AC 26 ms
26,920 KB
testcase_16 AC 26 ms
26,924 KB
testcase_17 AC 27 ms
26,936 KB
testcase_18 AC 26 ms
26,936 KB
testcase_19 AC 26 ms
26,888 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