QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#591647 | #8635. 圆 | Frodo | 100 ✓ | 42ms | 203700kb | C++14 | 835b | 2024-09-26 17:01:13 | 2024-09-26 17:01:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=5100,mod=998244353;
int n,fac[N],ifac[N],dp[N][N],ans=0;
int poww(int a,int b){
int ret=1;
while(b){
if(b&1) ret=ret*a%mod;
b>>=1,a=a*a%mod;
}
return ret;
}
int inv(int a){return poww(a,mod-2);}
void init(){
n=5e3;
fac[0]=1;
for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
ifac[n]=inv(fac[n]);
for(int i=n-1;i>=0;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}
int invC(int n,int m){return ifac[n]*fac[m]%mod*fac[n-m]%mod;}
signed main(){
init();
cin>>n;
if(n==3){cout<<"1\n";return 0;}
dp[0][0]=1;
for(int i=1;i<n;i++) for(int j=1;j<n;j++) dp[i][j]=(dp[i-1][j-1]+dp[i-1][j-2]+dp[i-1][j-3])%mod;
for(int i=1;i<n;i++) ans=(ans+1-(dp[i][n-1]+dp[i][n-2]+dp[i][n-3])*invC(n-1,i)%mod+mod)%mod;
cout<<ans+2<<'\n';
return 0;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 1ms
memory: 3644kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 1ms
memory: 3804kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 0ms
memory: 5644kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 1ms
memory: 3636kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 1ms
memory: 7840kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 2ms
memory: 12224kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 4ms
memory: 24280kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 35ms
memory: 198616kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 42ms
memory: 203428kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 31ms
memory: 203700kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"