QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#657974 | #9486. Random Mex | ucup-team173# | WA | 55ms | 253184kb | C++20 | 1.4kb | 2024-10-19 15:54:19 | 2024-10-19 15:54:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 8005;
const int Mod = 998244353;
int S[MAXN][MAXN], iFac[MAXN], inv[MAXN], Fac[MAXN];
int Fpow(int x, int k) {
int ans = 1;
for (x %= Mod; k; k >>= 1, x = 1ll * x * x % Mod) {
if (k & 1) ans = 1ll * ans * x % Mod;
}
return ans;
}
void solve() {
int maxN = 8001;
S[0][0] = 1;
for (int i = 1; i <= maxN; i++) {
S[i][0] = 0;
for (int j = 1; j <= i; j++) {
S[i][j] = (1ll * S[i - 1][j] * j + S[i - 1][j - 1]) % Mod;
}
}
inv[0] = 1;
for (int i = 1; i <= maxN; i++) {
inv[i] = Fpow(i, Mod - 2);
}
iFac[0] = 1;
for (int i = 1; i <= maxN; i++) {
iFac[i] = 1ll * iFac[i - 1] * inv[i] % Mod;
}
Fac[0] = 1;
for (int i = 1; i <= maxN; i++) {
Fac[i] = 1ll * Fac[i - 1] * i % Mod;
}
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
int ans = ((Fpow((1 + inv[m]), n) % Mod
- 1
- 1ll * Fpow(inv[m], n) % Mod * S[n][m + 1] % Mod * Fac[n] % Mod) % Mod + Mod) % Mod;
cout << ans << '\n';
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 55ms
memory: 252676kb
input:
4 3 2 1 1 20 23 8000 8000
output:
374341634 1 111675632 994279778
result:
ok 4 tokens
Test #2:
score: -100
Wrong Answer
time: 31ms
memory: 253184kb
input:
5 60 26 33 95 18 89 82 12 77 36
output:
66651341 254913692 403396795 942853338 593372754
result:
wrong answer 1st words differ - expected: '945602338', found: '66651341'