QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#619141 | #8635. 圆 | zhicheng | 100 ✓ | 22ms | 101112kb | C++14 | 738b | 2024-10-07 13:15:58 | 2024-10-07 13:16:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5010,mod=998244353;
int dp[N][N],fac[N];
int qpow(int a,int b){
int ans=1;
while(b){
if(b&1){
ans=1ll*ans*a%mod;
}
a=1ll*a*a%mod;
b>>=1;
}
return ans;
}
int main(){
int n,ans=0;
scanf("%d",&n);
fac[0]=1;
for(int i=1;i<=n;i++){
fac[i]=1ll*fac[i-1]*i%mod;
}
dp[1][1]=1;
for(int i=2;i<=n;i++){
for(int j=1;j<=i;j++){
dp[i][j]=(0ll+dp[i-1][j-1]+dp[i-2][j-1]+(i>=3)*dp[i-3][j-1])%mod;
}
}
for(int i=1;i<=n;i++){
dp[n][i]=(0ll+dp[n][i]+dp[n-1][i]+dp[n-2][i])%mod;
dp[n][i]=1ll*dp[n][i]*fac[n-i]%mod*fac[i-1]%mod;
ans=(ans+1ll*i*(dp[n][i]+mod-dp[n][i-1]))%mod;
}
printf("%lld",1ll*ans*qpow(fac[n-1],mod-2)%mod);
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3904kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 0ms
memory: 3908kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 0ms
memory: 3840kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 0ms
memory: 3936kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 1ms
memory: 5912kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 1ms
memory: 8128kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 0ms
memory: 13932kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 22ms
memory: 98292kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 7ms
memory: 101112kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 17ms
memory: 100740kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"