QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#290456 | #384. 泳池 | MoRanSky | 100 ✓ | 158ms | 11792kb | C++20 | 2.9kb | 2023-12-25 00:37:42 | 2023-12-25 00:37:42 |
Judging History
answer
// Skyqwq
#include <iostream>
#include <cstdio>
#include <cstring>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long LL;
template <typename T> void chkMax(T &x, T y) { if (y > x) x = y; }
template <typename T> void chkMin(T &x, T y) { if (y < x) x = y; }
template <typename T> void inline read(T &x) {
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
template <typename T> void print(T x) {
if (x < 0) { putchar('-'); print(-x); return ; }
if (x >= 10) print(x / 10);
putchar((x % 10) + '0');
}
const int N = 1005, P = 998244353;
int n, K, x, y, p, pw[N], f[N][N], s[N][N], ans;
void inline add(int &x, int y) {
x += y;
if (x >= P) x -= P;
}
int inline power(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = (LL)res * a % P;
a = (LL)a * a % P;
b >>= 1;
}
return res;
}
void inline clear() {
memset(pw, 0, sizeof pw);
memset(f, 0, sizeof f);
memset(s, 0, sizeof s);
}
void work1() {
for (int i = 0; i <= K; i++)
pw[i] = (LL)power(p, i) * (1 + P - p) % P;
for (int i = 0; i <= K + 1; i++) s[0][i] = 1;
int l = min(n, K);
for (int i = 1; i <= l; i++) {
int lim = i == 0 ? K : K / i;
for (int j = 0; j <= lim; j++) {
int v = 0;
for (int x = 1; x <= i; x++)
add(v, (LL)s[x - 1][j + 1] * s[i - x][j] % P);
f[i][j] = (LL)pw[j] * v % P;
}
for (int j = lim; ~j; j--)
s[i][j] = (s[i][j + 1] + f[i][j]) % P;
}
}
int F[N << 1], G[N << 1], H[N << 1], C[N << 1];
void inline mul(int *f, int *g, int *h) {
int l = 2 * K + 2;
for (int i = 0; i <= l; i++) h[i] = 0;
for (int i = 0; i <= K + 1; i++) {
for (int j = 0; j <= K + 1; j++) {
add(h[i + j], (LL)f[i] * g[j] % P);
}
}
}
int inline work2() {
memset(F, 0, sizeof F);
memset(G, 0, sizeof G);
for (int i = 0; i <= K; i++) F[i] = s[i][0];
for (int i = 1; i <= K + 1; i++) G[i] = (LL)(1 - p + P) * s[i - 1][1] % P;
for (int i = 1; i <= K + 1; i++) G[i] = (P - G[i]) % P;
add(G[0], 1);
mul(F, G, H);
for (int i = K + 1; i <= 2 * K + 2; i++) H[i] = 0;
int b = n;
while (b) {
for (int i = 0; i <= K + 1; i++)
F[i] = (i & 1) ? (P - G[i]) % P : G[i];
mul(F, G, C);
for (int i = 0; i <= K + 1; i++)
G[i] = C[i * 2];
mul(F, H, C);
for (int i = 0; i <= K; i++)
H[i] = C[i * 2 + (b & 1)];
b >>= 1;
}
return H[0];
}
int inline solve() {
if (K == -1) return 0;
if (K == 0) return power((1 - p + P) % P, n);
clear();
work1();
if (n <= K) return s[n][0];
else return work2();
}
int main() {
read(n), read(K), read(x), read(y);
p = (LL)x * power(y, P - 2) % P;
int ans = solve();
K--;
ans = (ans - solve() + P) % P;
printf("%d\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 0ms
memory: 11696kb
input:
1 949 139078994 990651604
output:
330219622
result:
ok single line: '330219622'
Test #2:
score: 5
Accepted
time: 0ms
memory: 11468kb
input:
1 944 145496294 755116222
output:
930631836
result:
ok single line: '930631836'
Test #3:
score: 5
Accepted
time: 0ms
memory: 11736kb
input:
10 8 144842939 146358488
output:
375036401
result:
ok single line: '375036401'
Test #4:
score: 5
Accepted
time: 0ms
memory: 11720kb
input:
10 9 147875518 748368567
output:
709619968
result:
ok single line: '709619968'
Test #5:
score: 5
Accepted
time: 2ms
memory: 11560kb
input:
10 10 149567138 375202482
output:
38319127
result:
ok single line: '38319127'
Test #6:
score: 5
Accepted
time: 0ms
memory: 11732kb
input:
947 7 151913594 368520363
output:
141204133
result:
ok single line: '141204133'
Test #7:
score: 5
Accepted
time: 0ms
memory: 11504kb
input:
987 8 153223269 950558887
output:
846391446
result:
ok single line: '846391446'
Test #8:
score: 5
Accepted
time: 0ms
memory: 11736kb
input:
970 9 154292819 361838243
output:
181568951
result:
ok single line: '181568951'
Test #9:
score: 5
Accepted
time: 0ms
memory: 11444kb
input:
980 97 156846631 527638170
output:
20802473
result:
ok single line: '20802473'
Test #10:
score: 5
Accepted
time: 0ms
memory: 11452kb
input:
966 98 157883413 937194648
output:
179742710
result:
ok single line: '179742710'
Test #11:
score: 5
Accepted
time: 5ms
memory: 11792kb
input:
967 99 159400444 542443155
output:
238231981
result:
ok single line: '238231981'
Test #12:
score: 5
Accepted
time: 53ms
memory: 11560kb
input:
989 948 161746901 535761035
output:
876635506
result:
ok single line: '876635506'
Test #13:
score: 5
Accepted
time: 4ms
memory: 11660kb
input:
942 978 162609094 923732105
output:
236028500
result:
ok single line: '236028500'
Test #14:
score: 5
Accepted
time: 57ms
memory: 11740kb
input:
982 942 141042310 163263932
output:
741489934
result:
ok single line: '741489934'
Test #15:
score: 5
Accepted
time: 0ms
memory: 11692kb
input:
999971965 10 166090637 328362110
output:
412492049
result:
ok single line: '412492049'
Test #16:
score: 5
Accepted
time: 0ms
memory: 11552kb
input:
999975613 10 167334775 910367865
output:
8045707
result:
ok single line: '8045707'
Test #17:
score: 5
Accepted
time: 5ms
memory: 11432kb
input:
999975485 96 168371557 321679990
output:
549861210
result:
ok single line: '549861210'
Test #18:
score: 5
Accepted
time: 3ms
memory: 11548kb
input:
999980766 100 77923439 169888588
output:
278412314
result:
ok single line: '278412314'
Test #19:
score: 5
Accepted
time: 158ms
memory: 11556kb
input:
999993900 993 170990906 487479917
output:
265726301
result:
ok single line: '265726301'
Test #20:
score: 5
Accepted
time: 152ms
memory: 11500kb
input:
999974266 969 172060456 897003626
output:
219439784
result:
ok single line: '219439784'
Extra Test:
score: 0
Extra Test Passed