QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#624690 | #8635. 圆 | msk_sama | 100 ✓ | 223ms | 199540kb | C++14 | 1.2kb | 2024-10-09 16:26:03 | 2024-10-09 16:26:05 |
Judging History
answer
#include <bits/stdc++.h>
#define MISAKA main
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define _rep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
inline int read(){
char ch=getchar();int f=1,x=0;
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*f;
}
const double eps=1e-9;
const int N=5010,inf=1e9,mod=998244353;
int n,f[N][N],g[N],h[N],c[N][N],ans;
int add(int x,int y){x+=y;return x>=mod?x-mod:x;}
int del(int x,int y){x-=y;return x<0?x+mod:x;}
ll qp(ll a,ll b){ll r=1;for(;b;b>>=1,a=a*a%mod)if(b&1)r=r*a%mod;return r;}
void solve(int l,int r){
memset(f,0,sizeof(f));f[l][1]=1;
rep(i,l+1,r)rep(j,1,n)
f[i][j]=add(f[i-1][j-1],add(i>1?f[i-2][j-1]:0,i>2?f[i-3][j-1]:0));
rep(i,1,n) g[i]=add(g[i],f[r][i]);
}
signed MISAKA(){
n=read();c[0][0]=1;
rep(i,1,n){c[i][0]=1;rep(j,1,i)c[i][j]=add(c[i-1][j],c[i-1][j-1]);}
rep(l,1,3)rep(r,n-2,n)if(l<=r&&n+l-r<=3) solve(l,r);
rep(i,1,n) h[i]=1ll*g[i]*qp(c[n][i],mod-2)%mod,ans=add(ans,1ll*i*del(h[i],h[i-1])%mod);
printf("%d",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 37ms
memory: 101844kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 38ms
memory: 105688kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 34ms
memory: 102196kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 43ms
memory: 102704kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 39ms
memory: 106304kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 46ms
memory: 107044kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 45ms
memory: 113984kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 210ms
memory: 197124kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 207ms
memory: 199540kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 223ms
memory: 199152kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"