結果

問題 No.1044 正直者大学
ユーザー tarattata1tarattata1
提出日時 2020-05-01 22:59:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 2,394 bytes
コンパイル時間 757 ms
コンパイル使用メモリ 81,592 KB
実行使用メモリ 5,668 KB
最終ジャッジ日時 2023-08-26 15:39:47
合計ジャッジ時間 2,948 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
5,644 KB
testcase_01 AC 33 ms
5,624 KB
testcase_02 AC 32 ms
5,668 KB
testcase_03 AC 32 ms
5,580 KB
testcase_04 AC 33 ms
5,624 KB
testcase_05 AC 33 ms
5,580 KB
testcase_06 AC 49 ms
5,556 KB
testcase_07 AC 33 ms
5,580 KB
testcase_08 AC 33 ms
5,576 KB
testcase_09 AC 32 ms
5,580 KB
testcase_10 AC 32 ms
5,640 KB
testcase_11 AC 32 ms
5,564 KB
testcase_12 AC 33 ms
5,608 KB
testcase_13 AC 41 ms
5,612 KB
testcase_14 AC 33 ms
5,564 KB
testcase_15 AC 33 ms
5,564 KB
testcase_16 AC 41 ms
5,648 KB
testcase_17 AC 35 ms
5,564 KB
testcase_18 AC 38 ms
5,640 KB
testcase_19 AC 33 ms
5,612 KB
testcase_20 AC 33 ms
5,580 KB
testcase_21 AC 33 ms
5,668 KB
testcase_22 AC 33 ms
5,624 KB
testcase_23 AC 33 ms
5,652 KB
testcase_24 AC 33 ms
5,560 KB
testcase_25 AC 33 ms
5,612 KB
testcase_26 AC 32 ms
5,616 KB
testcase_27 AC 33 ms
5,588 KB
testcase_28 AC 33 ms
5,560 KB
testcase_29 AC 32 ms
5,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


const int max_comb=210000;
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;
}

ll calc(int n, int p)
{
    ll tmp0 = perm(n, n);
    ll tmp1 = comb(n - 1, p - 1);
    ll ans = tmp0 * tmp1 %MOD;
    return ans;
}

void solve()
{
    int n, m, K;
    scanf("%d%d%d", &n, &m, &K);

    pre_comb();

    ll ans = 0;
    int i;
    for (i = 1; i <= MIN(n, m); i++) {
        if (n + m - 2 * i >= K) {
            ll tmp0 = calc(n, i);
            ll tmp1 = calc(m, i);
            ll ans0 = tmp0 * tmp1 % MOD;
            ans0 = ans0 * minv(i) % MOD;
            ans = (ans + ans0) % MOD;
        }
    }

    printf("%lld\n", ans);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}

0