QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#875825 | #10014. Bottles | asdfsdf# | AC ✓ | 14ms | 8528kb | C++23 | 1.4kb | 2025-01-30 13:23:00 | 2025-01-30 13:23:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define MOD 998244353
#define MAX 303030
ll mpow(ll x, ll y = MOD - 2) {
ll mul = x;
ll ans = 1;
while (y) {
if (y & 1) ans = (ans * mul) % MOD;
y >>= 1;
mul = (mul * mul) % MOD;
}
return ans;
}
ll ifact[MAX];
ll fact[MAX];
inline ll C(int N, int R) {
ll res = fact[N] * ifact[R];
res %= MOD;
res = res * ifact[N - R];
res %= MOD;
return res;
}
inline ll P(int N, int R) {
ll res = fact[N] * ifact[N - R];
res %= MOD;
return res;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int i;
fact[0] = 1;
const int X = 300'010;
for (i = 1; i <= X; i++) fact[i] = (fact[i - 1] * i) % MOD;
ifact[X] = mpow(fact[X]);
for (i = X; i >= 1; i--) ifact[i - 1] = (ifact[i] * i) % MOD;
int e, p, w, t;
cin >> e >> p >> w >> t;
int N = e + p + w;
ll sum = 0;
for (i = 1; i <= N - e + 1; i++) {
ll mul = C(N - i, e - 1);
if (p + t <= i) mul *= mpow(N - i - e + 1 + t, p), mul %= MOD;
else if (t < i) {
mul *= mpow(N - i - e + 1 + t, i - t);
mul %= MOD;
mul *= P(N - e - i + t, p - i + t);
mul %= MOD;
}
else {
mul *= C(N - e, w);
mul %= MOD;
mul *= fact[p];
mul %= MOD;
}
sum = (sum + mul) % MOD;
}
ll div = C(N, w);
div %= MOD;
div *= C(N - w, e);
div %= MOD;
div *= fact[p];
div %= MOD;
sum *= mpow(div);
sum %= MOD;
cout << sum;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 8332kb
input:
1 1 2 1
output:
249561089
result:
ok answer is '249561089'
Test #2:
score: 0
Accepted
time: 2ms
memory: 8452kb
input:
1 1 1 42
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 8288kb
input:
2 2 2 2
output:
987152750
result:
ok answer is '987152750'
Test #4:
score: 0
Accepted
time: 13ms
memory: 8496kb
input:
12912 83717 73177 1920
output:
685360162
result:
ok answer is '685360162'
Test #5:
score: 0
Accepted
time: 3ms
memory: 8392kb
input:
1 1 1 3
output:
1
result:
ok answer is '1'
Test #6:
score: 0
Accepted
time: 10ms
memory: 8440kb
input:
100000 100000 100000 100000
output:
884123454
result:
ok answer is '884123454'
Test #7:
score: 0
Accepted
time: 14ms
memory: 8388kb
input:
100000 100000 100000 1
output:
37972278
result:
ok answer is '37972278'
Test #8:
score: 0
Accepted
time: 4ms
memory: 8520kb
input:
100000 100000 1 100000
output:
847064892
result:
ok answer is '847064892'
Test #9:
score: 0
Accepted
time: 5ms
memory: 8516kb
input:
100000 1 100000 100000
output:
847064892
result:
ok answer is '847064892'
Test #10:
score: 0
Accepted
time: 9ms
memory: 8192kb
input:
1 100000 100000 100000
output:
151826985
result:
ok answer is '151826985'
Test #11:
score: 0
Accepted
time: 2ms
memory: 8516kb
input:
100000 1 1 1
output:
587783175
result:
ok answer is '587783175'
Test #12:
score: 0
Accepted
time: 10ms
memory: 8492kb
input:
1 100000 1 1
output:
659649092
result:
ok answer is '659649092'
Test #13:
score: 0
Accepted
time: 2ms
memory: 8272kb
input:
1 1 100000 1
output:
217932349
result:
ok answer is '217932349'
Test #14:
score: 0
Accepted
time: 2ms
memory: 8528kb
input:
1 1 1 100000
output:
1
result:
ok answer is '1'
Test #15:
score: 0
Accepted
time: 4ms
memory: 8472kb
input:
95749 84022 2256 71002
output:
89255997
result:
ok answer is '89255997'
Test #16:
score: 0
Accepted
time: 4ms
memory: 8436kb
input:
66015 47097 73639 95827
output:
928194339
result:
ok answer is '928194339'
Test #17:
score: 0
Accepted
time: 4ms
memory: 8508kb
input:
95944 17006 29658 23200
output:
771575343
result:
ok answer is '771575343'
Test #18:
score: 0
Accepted
time: 5ms
memory: 8336kb
input:
9257 55034 17879 46323
output:
191492058
result:
ok answer is '191492058'
Test #19:
score: 0
Accepted
time: 5ms
memory: 8320kb
input:
76497 54324 46028 86026
output:
796696990
result:
ok answer is '796696990'
Test #20:
score: 0
Accepted
time: 9ms
memory: 8292kb
input:
57314 82829 23655 7714
output:
800572449
result:
ok answer is '800572449'
Test #21:
score: 0
Accepted
time: 4ms
memory: 8484kb
input:
74146 23222 26306 36160
output:
356496909
result:
ok answer is '356496909'
Test #22:
score: 0
Accepted
time: 3ms
memory: 8292kb
input:
25022 46653 31214 67195
output:
598439319
result:
ok answer is '598439319'
Test #23:
score: 0
Accepted
time: 6ms
memory: 8480kb
input:
11126 87011 10322 26510
output:
706916846
result:
ok answer is '706916846'
Test #24:
score: 0
Accepted
time: 4ms
memory: 8380kb
input:
22900 48667 11506 19337
output:
398909903
result:
ok answer is '398909903'
Test #25:
score: 0
Accepted
time: 10ms
memory: 8512kb
input:
11972 87699 84749 79973
output:
505283863
result:
ok answer is '505283863'
Test #26:
score: 0
Accepted
time: 6ms
memory: 8492kb
input:
77951 3071 79294 22287
output:
18979044
result:
ok answer is '18979044'
Test #27:
score: 0
Accepted
time: 2ms
memory: 8508kb
input:
69840 7597 69452 76260
output:
277837253
result:
ok answer is '277837253'
Test #28:
score: 0
Accepted
time: 5ms
memory: 8236kb
input:
76297 26248 57269 89866
output:
1
result:
ok answer is '1'
Test #29:
score: 0
Accepted
time: 2ms
memory: 8388kb
input:
74522 42427 38267 85979
output:
1
result:
ok answer is '1'
Test #30:
score: 0
Accepted
time: 7ms
memory: 8480kb
input:
32742 93389 40961 91991
output:
760235193
result:
ok answer is '760235193'
Test #31:
score: 0
Accepted
time: 6ms
memory: 8516kb
input:
11938 47548 91651 93913
output:
595870233
result:
ok answer is '595870233'
Test #32:
score: 0
Accepted
time: 8ms
memory: 8480kb
input:
25019 42986 53788 13964
output:
919492573
result:
ok answer is '919492573'
Test #33:
score: 0
Accepted
time: 9ms
memory: 8520kb
input:
81219 69788 40243 1125
output:
163847265
result:
ok answer is '163847265'
Test #34:
score: 0
Accepted
time: 1ms
memory: 8496kb
input:
2933 5015 40518 51856
output:
1
result:
ok answer is '1'