結果

問題 No.1596 Distance Sum in 2D Plane
ユーザー ぷらぷら
提出日時 2021-07-09 21:46:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 2,017 ms
コンパイル使用メモリ 199,556 KB
実行使用メモリ 12,940 KB
最終ジャッジ日時 2023-09-14 08:24:30
合計ジャッジ時間 5,585 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
12,788 KB
testcase_01 AC 12 ms
12,720 KB
testcase_02 AC 174 ms
12,760 KB
testcase_03 AC 172 ms
12,720 KB
testcase_04 AC 175 ms
12,704 KB
testcase_05 AC 172 ms
12,840 KB
testcase_06 AC 174 ms
12,940 KB
testcase_07 AC 173 ms
12,680 KB
testcase_08 AC 172 ms
12,776 KB
testcase_09 AC 172 ms
12,760 KB
testcase_10 AC 172 ms
12,704 KB
testcase_11 AC 145 ms
12,908 KB
testcase_12 AC 145 ms
12,724 KB
testcase_13 AC 144 ms
12,928 KB
testcase_14 AC 11 ms
12,712 KB
testcase_15 AC 11 ms
12,724 KB
testcase_16 AC 11 ms
12,840 KB
testcase_17 AC 11 ms
12,776 KB
testcase_18 AC 11 ms
12,692 KB
testcase_19 AC 11 ms
12,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 1000000007;

long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}

long long fac[400005], finv[400005], inv[400005];

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

long long 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] % mod) % mod;
}

int main() {
    int N,M;
    cin >> N >> M;
    long long ans = 0;
    COMinit();
    ans += COM(N+N,N)*(2*N)%mod;
    for(int i = 0; i < M; i++) {
        int t,x,y;
        cin >> t >> x >> y;
        if(t == 1) {
            ans += mod-COM(x+y,x)*COM(N-x-1+N-y,N-x-1)%mod;
            ans %= mod;
        }
        else {
            ans += mod-COM(x+y,x)*COM(N-x+N-y-1,N-y-1)%mod;
            ans %= mod;
        }
    }
    cout << ans << endl;
}
0