QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#590996 | #8635. 圆 | zhenghanyun | 90 | 79ms | 394872kb | C++14 | 1.4kb | 2024-09-26 13:32:19 | 2024-09-26 13:32:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5005;
const int mod = 998244353;
ll n, sum = 1, ans = 1, C[N][N], dp[N][N], t[N];
inline ll qpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) {
res = res * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return res;
}
inline ll inv(ll a) {
return qpow(a, mod - 2);
}
int main() {
#ifdef LOCAL
assert(freopen("T1.in", "r", stdin));
assert(freopen("T1.out", "w", stdout));
#endif
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n;
--n;
C[0][0] = 1;
for (int i = 1; i <= n; ++i) {
C[i][0] = 1;
for (int j = 1; j <= i; ++j) {
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
}
}
dp[0][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
dp[i][j] = dp[i - 1][j - 1];
if (i > 1) {
dp[i][j] = (dp[i][j] + dp[i - 2][j - 1]) % mod;
}
if (i > 2) {
dp[i][j] = (dp[i][j] + dp[i - 3][j - 1]) % mod;
}
}
}
ans = 2;
for (int i = 1; i <= n; ++i) {
sum = sum * i % mod;
t[i] = (dp[n][i] + dp[n - 1][i] + dp[n - 2][i]) % mod;
t[i] = (C[n][i] - t[i] + mod) % mod;
t[i] = (t[i] * sum) % mod;
}
sum = 1;
for (int i = 1; i <= n; ++i) {
sum = sum * (n - i + 1) % mod;
ans = (ans + t[i] * inv(sum)) % mod;
}
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5624kb
input:
3
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'
Test #2:
score: 10
Accepted
time: 1ms
memory: 5768kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 1ms
memory: 5780kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 1ms
memory: 5652kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 2ms
memory: 13928kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 0ms
memory: 20300kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 0ms
memory: 44864kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 79ms
memory: 381784kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 63ms
memory: 394752kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 76ms
memory: 394872kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"