QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#621629 | #8635. 圆 | larryyu | 100 ✓ | 15ms | 202380kb | C++20 | 957b | 2024-10-08 15:47:23 | 2024-10-08 15:47:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mo=998244353;
int n;
int dp[5050][5050];
int frac[5050],inv[5050];
int po(int x,int y){
int z=1;
while(y){
if(y%2) z*=x,z%=mo;
x*=x,x%=mo;
y/=2;
}
return z;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(nullptr);
cin>>n;
if(n==3) cout<<1,exit(0);
if(n==4) cout<<2,exit(0);
dp[2][1]=1;
for(int i=3;i<=n;i++){
for(int j=1;j<i;j++){
dp[i][j]=(dp[i-1][j-1]+dp[i-2][j-1]+dp[i-3][j-1])%mo;
}
}
frac[0]=1,inv[0]=1;
for(int i=1;i<=n;i++){
frac[i]=frac[i-1]*i%mo;
inv[i]=po(frac[i],mo-2);
}
int ans=0;
for(int i=1;i<=n;i++){
ans+=dp[n-2][i]*frac[i]%mo*3%mo*n%mo*frac[n-i-1]%mo*inv[n]%mo*(i+1)%mo;
ans%=mo;
ans+=dp[n-3][i]*frac[i]%mo*2%mo*n%mo*frac[n-i-1]%mo*inv[n]%mo*(i+1)%mo;
ans%=mo;
ans+=dp[n-4][i]*frac[i]%mo*1%mo*n%mo*frac[n-i-1]%mo*inv[n]%mo*(i+1)%mo;
ans%=mo;
}
cout<<ans;
return 0;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3676kb
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: 0ms
memory: 3708kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 0ms
memory: 3712kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 0ms
memory: 8004kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 2ms
memory: 11928kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 0ms
memory: 24196kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 11ms
memory: 192344kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 15ms
memory: 202380kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 15ms
memory: 200520kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"