QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#491046 | #8635. 圆 | KiharaTouma# | 40 | 55ms | 199616kb | C++23 | 864b | 2024-07-25 17:06:10 | 2024-07-25 17:06:11 |
Judging History
answer
//qoj8635
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5010;
const ll P = 998244353;
int n;
ll f[N][N], ans, fac[N];
ll qp(ll x, ll y){
ll ans = 1;
while(y){
if(y & 1){
ans = ans * x % P;
}
x = x * x % P;
y >>= 1;
}
return ans;
}
int main(){
scanf("%d", &n);
if(n <= 3){
puts("1");
return 0;
}
f[1][1] = fac[1] = 1;
for(int i = 2; i <= n; ++ i){
fac[i] = fac[i-1] * i % P;
for(int j = 1; j <= n; ++ j){
f[i][j] = (f[i-1][j-1] + f[i-2][j-1]) % P;
if(i > 3) f[i][j] = (f[i][j] + f[i-3][j-1]) % P;
}
}
for(int i = 1; i <= n; ++ i){
ll tmp = (f[n-3][i-1] * 2 + f[n-4][i-1] + f[n-2][i]) % P;
// printf("%d %d\n", i, tmp);
ans = (ans + tmp * i % P * fac[i-1] % P * fac[n-i] % P);
}
printf("%lld\n", ans * qp(fac[n-1], P-2) % P);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3820kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 0ms
memory: 3816kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 0ms
memory: 3976kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 0ms
memory: 3988kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 0
Wrong Answer
time: 1ms
memory: 8056kb
input:
100
output:
107813204
result:
wrong answer 1st numbers differ - expected: '41620761', found: '107813204'
Test #6:
score: 0
Wrong Answer
time: 0ms
memory: 12244kb
input:
200
output:
407349093
result:
wrong answer 1st numbers differ - expected: '208771764', found: '407349093'
Test #7:
score: 0
Wrong Answer
time: 0ms
memory: 22552kb
input:
500
output:
155146794
result:
wrong answer 1st numbers differ - expected: '888621375', found: '155146794'
Test #8:
score: 0
Wrong Answer
time: 50ms
memory: 193188kb
input:
4798
output:
-43971448
result:
wrong answer 1st numbers differ - expected: '319137015', found: '-43971448'
Test #9:
score: 0
Wrong Answer
time: 50ms
memory: 199616kb
input:
4999
output:
-129657375
result:
wrong answer 1st numbers differ - expected: '818467659', found: '-129657375'
Test #10:
score: 0
Wrong Answer
time: 55ms
memory: 199468kb
input:
5000
output:
992693820
result:
wrong answer 1st numbers differ - expected: '142907477', found: '992693820'