QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#619588 | #8635. 圆 | sio_ | 100 ✓ | 18ms | 3820kb | C++14 | 1.1kb | 2024-10-07 14:43:12 | 2024-10-07 14:43:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=5e3+5,mod=998244353;
int f[maxn][3],ans,n,fac[maxn],inv[maxn];
int fast_power(int x,int k)
{
if(k==0) return 1;
int tmp=fast_power(x,k/2);
if(k%2==0) return tmp*tmp%mod;
else return tmp*tmp%mod*x%mod;
}
int C(int x,int y){return fac[x]*inv[y]%mod*inv[x-y]%mod;}
signed main()
{
cin>>n,f[1][0]=1,inv[0]=inv[1]=fac[0]=fac[1]=1;
for(int i=2;i<=n;i++)
{
fac[i]=fac[i-1]*i%mod,inv[i]=fast_power(fac[i],mod-2);
// cout<<fac[i]<<" "<<inv[i]<<"\n";
for(int k=i;k>=1;k--)
{
f[k][2]=f[k][1],f[k][1]=f[k][0];
f[k][0]=(f[k-1][0]+f[k-1][1]+f[k-1][2])%mod;
}
}
for(int i=1;i<=n;i++)
{
int sum=(f[i][0]+f[i][1]+f[i][2])%mod;
// cout<<sum<<" "<<(fac[n]*fast_power(C(n,i),mod-2)%mod)*(C(n,i)-sum*n%mod*fast_power(i,mod-2)%mod+mod)%mod<<"\n";
(ans+=(fac[n]*fast_power(C(n,i),mod-2)%mod)*(C(n,i)-sum*n%mod*fast_power(i,mod-2)%mod+mod)%mod)%mod;
ans%=mod;
}
cout<<ans*inv[n]%mod+1;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3708kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 0ms
memory: 3508kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 0ms
memory: 3708kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 0ms
memory: 3512kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 0ms
memory: 3564kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 1ms
memory: 3652kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 1ms
memory: 3712kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 14ms
memory: 3804kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 18ms
memory: 3760kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 18ms
memory: 3820kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"