結果

問題 No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
ユーザー potoooooooopotoooooooo
提出日時 2019-12-11 23:02:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 5,000 ms
コード長 1,610 bytes
コンパイル時間 1,456 ms
コンパイル使用メモリ 167,900 KB
実行使用メモリ 80,308 KB
最終ジャッジ日時 2023-09-06 13:33:07
合計ジャッジ時間 4,415 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
61,988 KB
testcase_01 AC 57 ms
61,928 KB
testcase_02 AC 55 ms
62,036 KB
testcase_03 AC 56 ms
62,160 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 56 ms
61,968 KB
testcase_06 AC 57 ms
62,016 KB
testcase_07 AC 56 ms
61,932 KB
testcase_08 AC 57 ms
61,944 KB
testcase_09 AC 58 ms
62,100 KB
testcase_10 AC 58 ms
62,008 KB
testcase_11 AC 58 ms
62,128 KB
testcase_12 AC 57 ms
62,032 KB
testcase_13 AC 57 ms
62,156 KB
testcase_14 AC 57 ms
62,140 KB
testcase_15 AC 60 ms
62,980 KB
testcase_16 AC 68 ms
65,676 KB
testcase_17 AC 77 ms
69,896 KB
testcase_18 AC 82 ms
72,768 KB
testcase_19 AC 77 ms
70,096 KB
testcase_20 AC 88 ms
76,112 KB
testcase_21 AC 70 ms
67,188 KB
testcase_22 AC 88 ms
75,108 KB
testcase_23 AC 68 ms
65,840 KB
testcase_24 AC 88 ms
75,496 KB
testcase_25 AC 94 ms
78,404 KB
testcase_26 AC 98 ms
80,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MAX_N 2500000
long long inv[MAX_N];
long long factorial[MAX_N];
long long inv_factorial[MAX_N];

void init(){
    for (int i = 1; i < MAX_N; i++) {
        if (i == 1) inv[i] = 1;
        else {
            inv[i] = (mod - (mod / i) * inv[mod % i]) % mod;
            if (inv[i] < 0) inv[i] += mod;
        }
    }
    factorial[0] = 1; inv_factorial[0] = 1;
    for (int i = 1; i < MAX_N; i++) {
        factorial[i] = factorial[i-1] * i;
        factorial[i] %= mod;
        inv_factorial[i] = inv_factorial[i-1] * inv[i];
        inv_factorial[i] %= mod;
    }
}

long long combination(int n, int r) {
    long long ret = factorial[n] * inv_factorial[r];
    ret %= mod;
    ret *= inv_factorial[n-r];
    return ret % mod;
}

int if0() {
    cout << 1 << endl;
    return 0;
}

int main() {
    int x, y, z; cin >> x >> y >> z;
    int n = x + y + z;
    if (n == 0) return if0();
    init();

    vector<long long> w(n+1, 0);
    for (int i = 1; i <= n; i++) {
        w[i] = combination(x+i-1, x) * combination(y+i-1, y) % mod * combination(z+i-1, z) % mod;
    }

    // c = {1 - (x-1)^(n+1)} / 2(1 - x/2)     
    vector<long long> c(n+1, 0); c[0] = 1; 
    for (int i = 0; i <= n; i++) {
        if ((n + 1 - i) & 1) c[i] += combination(n+1, i);
        else c[i] += mod - combination(n+1, i);
        if (i) c[i] += c[i-1];
        c[i] = c[i] % mod * inv[2] % mod;
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = (ans + c[i] * w[i] % mod) % mod;
    }
    cout << ans << endl;
    return 0;
}
0