QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#666338 | #8635. 圆 | zhuluoan | 100 ✓ | 71ms | 3760kb | C++14 | 1.6kb | 2024-10-22 17:54:59 | 2024-10-22 17:55:12 |
Judging History
answer
#define mod 998244353
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5005;
const int lim = maxn - 1;
ll fac[maxn], inv[maxn];
int n, sum[maxn];
inline ll qpow(ll x, ll y) {
ll ans = 1, base = x;
while(y) {
if(y & 1) {
ans = ans * base % mod;
}
y >>= 1;
base = base * base % mod;
}
return ans;
}
inline void init() {
fac[0] = 1;
for(int i = 1; i <= lim; ++i) {
fac[i] = fac[i - 1] * i % mod;
}
for(int i = 0; i <= lim; ++i) {
inv[i] = qpow(fac[i], mod - 2);
}
}
inline ll C(int x, int y) {
if(x < y) {
return 0;
}
return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main() {
ios::sync_with_stdio(false);
init();
cin >> n;
assert(n >= 3);
if(n == 3) {
cout << 1 << endl;
return 0;
}
for(int k = 1; k <= n - 1; ++k) {
ll g = 0;
for(int len = n - 3; len <= n - 1; ++len) {
for(int a = 0; a <= k; ++a) {
int b2c = len - k;
int bc = k - a;
int c = b2c - bc;
int b = k - a - c;
if(a >= 0 && b >= 0 && c >= 0) {
g = (g + C(k, a) * C(k - a, b) % mod * fac[k] % mod) % mod;
//cout<<k<<" "<<a<<" "<<b<<" "<<c<<"\n";
}
}
}
sum[k + 1] = g * fac[n - k - 1] % mod;
}
// for(int k = 1; k <= n; ++k) {
// cout << sum[k] << ' ';
// } cout << endl;
ll ans = 0;
for(int k = 1; k <= n; ++k) {
ll pdf = (sum[k] - sum[k - 1]) % mod * inv[n - 1] % mod;
ans = (ans + pdf * k % mod) % mod;
}
ans = (ans % mod + mod) % mod;
cout << ans << endl;
return 0;
}
// a + b + c = k
// a + 2b + 3c = len
// C(k, a) * C(k - a, b)
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 1ms
memory: 3624kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 1ms
memory: 3760kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 1ms
memory: 3636kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 1ms
memory: 3628kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 1ms
memory: 3716kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 0ms
memory: 3652kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 0ms
memory: 3652kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 65ms
memory: 3652kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 71ms
memory: 3648kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 71ms
memory: 3664kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"