QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#619664 | #8635. 圆 | qijianci | 100 ✓ | 71ms | 101556kb | C++14 | 930b | 2024-10-07 14:57:08 | 2024-10-07 14:57:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5005,M=998244353;
int f[N][N],n,fac[N],inv[N],ans;
int qpow(int x,int y,int res=1){
while(y){
if(y&1)res=1ll*res*x%M;
x=1ll*x*x%M,y>>=1;
} return res;
}
int md(int x){if(x>=M)x-=M;return x;}
int C(int x,int y){
return 1ll*fac[x]*inv[y]%M*inv[x-y]%M;
}
signed main(){
ios::sync_with_stdio(false);
// freopen("color.in","r",stdin);
// freopen("color.out","w",stdout);
int i,j,k,l,r,x,y,z;
cin>>n,f[1][1]=1,fac[0]=inv[0]=1;
for(i=2;i<=n;++i)for(j=min(i-1,n-3);j>=i-3&&j>0;--j)
for(k=1;k<=n;++k)f[i][k+1]=md(f[i][k+1]+f[j][k]);
for(i=1;i<=n;++i)fac[i]=1ll*fac[i-1]*i%M;
inv[n]=qpow(fac[n],M-2);
for(i=n-1;i;--i)inv[i]=inv[i+1]*(i+1ll)%M;
for(i=n-2;i<=n;++i)for(j=1;j<=n;++j)
ans=(ans+1ll*f[i][j]*qpow(C(n-1,j-1),M-2)%M*j)%M;
printf("%d\n",ans);
return 0;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3856kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 0ms
memory: 3860kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 0ms
memory: 3872kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 0ms
memory: 3896kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 1ms
memory: 4228kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 1ms
memory: 4804kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 0ms
memory: 6824kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 71ms
memory: 97656kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 62ms
memory: 101532kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 61ms
memory: 101556kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"