結果

問題 No.940 ワープ ε=ε=ε=ε=ε=│;p>д<│
ユーザー potoooooooopotoooooooo
提出日時 2019-12-11 22:56:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,598 bytes
コンパイル時間 1,608 ms
コンパイル使用メモリ 167,592 KB
実行使用メモリ 68,980 KB
最終ジャッジ日時 2023-09-06 13:32:35
合計ジャッジ時間 5,079 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
50,400 KB
testcase_01 AC 46 ms
50,332 KB
testcase_02 AC 45 ms
50,156 KB
testcase_03 AC 45 ms
50,268 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 46 ms
50,316 KB
testcase_06 AC 46 ms
50,256 KB
testcase_07 AC 46 ms
50,236 KB
testcase_08 AC 46 ms
50,416 KB
testcase_09 AC 46 ms
50,240 KB
testcase_10 AC 46 ms
50,192 KB
testcase_11 AC 46 ms
50,176 KB
testcase_12 AC 47 ms
50,196 KB
testcase_13 AC 46 ms
50,428 KB
testcase_14 AC 46 ms
50,304 KB
testcase_15 AC 49 ms
50,960 KB
testcase_16 AC 56 ms
53,780 KB
testcase_17 AC 63 ms
58,240 KB
testcase_18 AC 68 ms
60,800 KB
testcase_19 AC 63 ms
58,184 KB
testcase_20 AC 75 ms
64,112 KB
testcase_21 AC 57 ms
55,336 KB
testcase_22 AC 73 ms
63,308 KB
testcase_23 AC 57 ms
54,104 KB
testcase_24 AC 74 ms
63,916 KB
testcase_25 AC 79 ms
66,620 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MAX_N 2000010
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] * inv[2] % mod;
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = (ans + c[i] * w[i]) % mod;
    }
    cout << ans << endl;
    return 0;
}
0