結果

問題 No.1044 正直者大学
ユーザー okok
提出日時 2020-05-03 20:41:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 2,164 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 82,976 KB
実行使用メモリ 9,456 KB
最終ジャッジ日時 2023-09-05 02:41:16
合計ジャッジ時間 3,074 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 10 ms
9,380 KB
testcase_06 AC 24 ms
9,456 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 7 ms
5,964 KB
testcase_13 AC 16 ms
6,968 KB
testcase_14 AC 7 ms
6,692 KB
testcase_15 AC 10 ms
8,800 KB
testcase_16 AC 17 ms
7,500 KB
testcase_17 AC 12 ms
5,760 KB
testcase_18 AC 13 ms
6,024 KB
testcase_19 AC 9 ms
4,852 KB
testcase_20 AC 6 ms
4,384 KB
testcase_21 AC 7 ms
4,500 KB
testcase_22 AC 4 ms
5,172 KB
testcase_23 AC 8 ms
7,960 KB
testcase_24 AC 7 ms
6,280 KB
testcase_25 AC 6 ms
6,268 KB
testcase_26 AC 7 ms
7,528 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

class binomial_coefficients {
	long long MAX_VAL;

public:

	vector<long long> fac, mmi;
	
	binomial_coefficients(){
	}
	
	binomial_coefficients(long long num){
		init(num);
	}
	
	~binomial_coefficients(){
		
	}
	
	void init(long long num){
		MAX_VAL = num+1; 
		fac.resize(MAX_VAL);
		mmi.resize(MAX_VAL);
		
		factorial_mod();
		modular_multiplicatibe_inverse();
	}
	
	void factorial_mod(){
		 fac[0] = 1;
		for(long long i = 1; i < MAX_VAL; fac[i] %= MOD, i++)
			fac[i] = fac[i - 1] * (i % MOD);
	}
	
	long long power(long long x, long long n){
		long long ans = 1;
		for(;n;n >>= 1, x *= x, ans %= MOD, x %= MOD)
			if(n&1)ans*=x;
		return ans % MOD;
	}
	
	void exgcd(long long a, long long b, long long &x, long long &y){
		if(b == 0){
			x = 1;
			y = 0;
			return ;
		}
		exgcd(b, a % b, y, x);
		y -= a / b * x;
	}
	
	void modular_multiplicatibe_inverse(){
		long long x, y;  
		exgcd(fac[MAX_VAL - 1], MOD, x, y);
		mmi[MAX_VAL-1] = x;
		// mmi[MAX_VAL-1] = power(fac[MAX_VAL-1], MOD-2);
		for(long long i = MAX_VAL - 2; i >= 0; mmi[i]%=MOD, i--)
			mmi[i] = mmi[i + 1] * ((i + 1) % MOD);
	}
	
	long long combination(long long n, long long r){
		return n < r ? 0 :fac[n] * (mmi[r] * mmi[n-r] % MOD) % MOD;
	}
};

signed main(){
	cout<<fixed<<setprecision(10);
	
	binomial_coefficients BC;
	int N, M, K;
	int ans = 0;
	
	cin>>N>>M>>K;
	
	BC.init((N+M) * 2);
	
	for(int i = 2; i <= N + M; i += 2){
		int A = 0, B = 0;
		int a = (i) / 2, b = (i) / 2;
		
		if(N + M - i < K) continue;
		
		if(N - a >= 0) A = BC.combination(N - a + (a - 1), a - 1) ;
		if(M - b >= 0) B = BC.combination(M - b + (b - 1), b - 1);
		ans += A * B % MOD * BC.power(i/2, MOD-2) % MOD;
		ans %= MOD;
	}
	
	
	ans *= BC.fac[N];
	ans %= MOD;
	ans *= BC.fac[M];
	ans %= MOD;
	
	cout<<ans<<endl;
	
	return 0;
}
0