-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathK_contestants.cpp
56 lines (48 loc) · 1.33 KB
/
K_contestants.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// iagorrr ;)
#include <bits/stdc++.h>
using namespace std;
using ull = long long;
vector<ull> facts(1e5+10, -1);
const ull MOD = 1000000007;
ull ft(ull k) {
if(facts[k] != -1) return facts[k];
facts[k] = (ft(k-1)*k)%MOD;
return facts[k];
}
ull aescb(ull a, ull b) { // a esoclhe b.
ull ans = (ft(a) / (ft(a-b) * ft(b))) % MOD;
return ans;
}
int main() {
facts[0] = 1;
facts[1] = 1;
int t;
cin >> t;
while(t--) {
ull A, B, C, c, K;
cin >> A >> B >> C >> K >> c;
ull V = K-c; // quero escolehr
ull v = A+B; // quantas posso escolher
// cout << "mats\n";
ull mats = aescb(C, c);
if(V > v or K < 3) {
cout << 0 << '\n';
continue;
}
ull onlya = 0;
if(A > V) onlya = aescb(A, V);
ull onlyb = 0;
if(B > V) onlyb = aescb(B, V);
// ull others = ft(V) / ft(V-v) * ft(v);
ull others = aescb(v, V);
//cout << "onlyb: " << onlyb << '\n';
//cout << "onlya: " << onlya << '\n';
//cout << "others: " << others << '\n';
//cout << "mats: " << mats << '\n';
others = ((others-onlya % MOD) + MOD ) % MOD;
others = ((others-onlyb % MOD) + MOD ) % MOD;
ull ans = ((others)*mats) % MOD;
cout << ans << '\n';
}
}
// WA on test 2.