QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#665679 | #8635. 圆 | Luckies | 100 ✓ | 58ms | 3812kb | C++20 | 1.4kb | 2024-10-22 14:43:06 | 2024-10-22 14:43:22 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e3 + 5, Mod = 998244353;
int n, c[N], fac[N], ans, inv[N];
int quickpow(int a, int b)
{
int res = 1;
while(b)
{
if(b & 1)
res = res * a % Mod;
a = a * a % Mod;
b >>= 1;
}
return res;
}
int Inv(int x)
{
return quickpow(fac[x], Mod - 2);
}
int C(int n, int m)
{
if(n < m)
return 0;
return fac[n] * inv[m] % Mod * inv[n - m] % Mod;
}
int calc(int k, int m)
{
if(k < 0 || m - 1 < 0 || m - 1 < k)
return 0;
if(!k)
return m == 1 ? 1 : 0;
int res = 0;
for(int a = 0; a <= k; a++)
{
int b = 3 * k - 2 * a - m + 1,
c = a + m - 1 - (k << 1);
if(b >= 0 && c >= 0)
res = (res + C(k, a) * C(k - a, b) % Mod) % Mod;
}
return res;
}
signed main()
{
cin >> n;
fac[0] = inv[0] = 1;
for(int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % Mod, inv[i] = Inv(i);
for(int k = (int)ceil(n * 1.0 / 3); k <= n - 2; k++)
{
int res = (calc(k - 2, n - 3) * 2 % Mod + calc(k - 2, n - 4) + calc(k - 1, n - 2)) % Mod;
res = (res * n % Mod * fac[k - 1] % Mod * fac[n - k] % Mod);
ans = (ans + res * k % Mod) % Mod;
}
cout << ans * inv[n] % Mod;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 1ms
memory: 3672kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 0ms
memory: 3568kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 1ms
memory: 3724kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 0ms
memory: 3568kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 1ms
memory: 3608kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 1ms
memory: 3608kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 1ms
memory: 3676kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 50ms
memory: 3812kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 58ms
memory: 3736kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 58ms
memory: 3684kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"