結果

問題 No.895 MESE
ユーザー tarattata1tarattata1
提出日時 2019-09-27 23:22:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 2,019 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 73,216 KB
実行使用メモリ 9,852 KB
最終ジャッジ日時 2023-10-25 06:38:15
合計ジャッジ時間 3,551 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
7,032 KB
testcase_01 AC 47 ms
7,032 KB
testcase_02 AC 47 ms
7,032 KB
testcase_03 AC 47 ms
7,032 KB
testcase_04 AC 46 ms
7,032 KB
testcase_05 AC 46 ms
7,032 KB
testcase_06 AC 46 ms
7,032 KB
testcase_07 AC 46 ms
7,032 KB
testcase_08 AC 47 ms
7,032 KB
testcase_09 AC 47 ms
7,032 KB
testcase_10 AC 46 ms
7,032 KB
testcase_11 AC 46 ms
7,032 KB
testcase_12 AC 47 ms
7,032 KB
testcase_13 AC 68 ms
8,796 KB
testcase_14 AC 64 ms
8,796 KB
testcase_15 AC 75 ms
8,796 KB
testcase_16 AC 70 ms
8,532 KB
testcase_17 AC 59 ms
8,796 KB
testcase_18 AC 82 ms
9,852 KB
testcase_19 AC 82 ms
9,852 KB
testcase_20 AC 83 ms
9,852 KB
testcase_21 AC 82 ms
9,852 KB
testcase_22 AC 82 ms
9,852 KB
testcase_23 AC 83 ms
9,852 KB
testcase_24 AC 82 ms
9,852 KB
testcase_25 AC 82 ms
9,852 KB
testcase_26 AC 82 ms
9,852 KB
testcase_27 AC 82 ms
9,852 KB
testcase_28 AC 83 ms
9,852 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:72:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   72 |     scanf("%d%d%d", &a, &b, &c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


const int max_comb=300000;
vector<ll> fac(max_comb+1); //n! (mod M)
vector<ll> ifac(max_comb+1); //k!^(-1) (mod M)

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll minv(ll x){
    return mpow( x, MOD-2 );
}

ll comb(int a, int b){     // C(a,b) = a! * b!^(-1) * (a-b)^(-1)
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

ll perm(int a, int b){     // P(a,b) = a! * (a-b)!^(-1)
    if(b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b] % MOD;
    return tmp * fac[a] % MOD;
}

void pre_comb()
{
    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 0; i<max_comb; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*minv(i+1) % MOD; // k!^(-1) (mod M)
    }
    return;
}

int main(int argc, char* argv[])
{
    int a,b,c;
    scanf("%d%d%d", &a, &b, &c);

    pre_comb();

    vector<ll> x(a+b+c);
    int i;
    x[0]=1;
    for(i=1; i<a+b+c; i++) {
        x[i]=x[i-1]*2%MOD;
    }

    ll sum=0;
    for(i=c; i<=a+b+c-2; i++) {
        ll val0 = x[i-1] * comb(i-1,c-1) %MOD;
        ll val1 = ((x[i-1]-1+MOD)%MOD)*comb(i-1,c-1)%MOD*(c-1)%MOD*minv(i-1)%MOD;
        ll val = (val0 + val1)%MOD;
        val = val*((comb(a+b-1,a-1) - (i>=b+c? comb(i-c,b): 0) +MOD)%MOD) %MOD;
        sum = (sum+val)%MOD;
    }
    printf("%lld\n", sum);

    return 0;
}
0