QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625546#8635. 圆ran_qwq100 ✓408ms199596kbC++202.7kb2024-10-09 19:45:102024-10-09 19:45:11

Judging History

This is the latest submission verdict.

  • [2024-10-09 19:45:11]
  • Judged
  • Verdict: 100
  • Time: 408ms
  • Memory: 199596kb
  • [2024-10-09 19:45:10]
  • Submitted

answer

#include<bits/stdc++.h>
#define il inline
#define ui unsigned int
#define ll long long
#define ull unsigned ll
#define lll __int128
#define db double
#define ldb long double
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define fir first
#define sec second
#define gc getchar
#define pc putchar
#define mst(a,x) memset(a,x,sizeof a)
#define mcp(a,b) memcpy(a,b,sizeof b)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pct __builtin_popcount
using namespace std;
const int N=5010,INF=0x3f3f3f3f,MOD=998244353; const ll INFll=0x3f3f3f3f3f3f3f3f;
il int rd() {int x=0,f=1; char ch=gc(); while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=gc();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc(); return x*f;}
il ll rdll() {ll x=0; int f=1; char ch=gc(); while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=gc();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc(); return x*f;}
il void wr(int x) {if(x==INT_MIN) return printf("-2147483648"),void(); if(x<0) return pc('-'),wr(-x); if(x<10) return pc(x+'0'),void(); wr(x/10),pc(x%10+'0');}
il void wrll(ll x) {if(x==LONG_LONG_MIN) return printf("-9223372036854775808"),void(); if(x<0) return pc('-'),wrll(-x); if(x<10) return pc(x+'0'),void(); wrll(x/10),pc(x%10+'0');}
il void wr(int x,char *s) {wr(x),printf("%s",s);}
il void wrll(ll x,char *s) {wrll(x),printf("%s",s);}
il int vmod(int x) {return x>=MOD?x-MOD:x;}
il int vadd(int x,int y) {return vmod(x+y);}
il int vsub(int x,int y) {return vmod(x-y+MOD);}
il int vmul(int x,int y) {return 1ll*x*y%MOD;}
il int qpow(int x,int y) {int res=1; for(;y;y>>=1,x=vmul(x,x)) if(y&1) res=vmul(res,x); return res;}
il void cadd(int &x,int y) {x=vmod(x+y);}
il void csub(int &x,int y) {x=vmod(x-y+MOD);}
il void cmul(int &x,int y) {x=vmul(x,y);}
il void cmax(int &x,int y) {x<y&&(x=y);}
il void cmaxll(ll &x,ll y) {x<y&&(x=y);}
il void cmin(int &x,int y) {x>y&&(x=y);}
il void cminll(ll &x,ll y) {x>y&&(x=y);}
int n,ans,fac[N],f[N],g[N],dp[N][N],C[N][N];
void sol(int l,int r) {
	mst(dp,0),dp[l][1]=1;
	for(int i=l+1;i<=r;i++) for(int j=1;j<=n;j++)
		dp[i][j]=vadd(vadd(dp[i-1][j-1],i>1?dp[i-2][j-1]:0),i>2?dp[i-3][j-1]:0);
	for(int i=1;i<=n;i++) cadd(g[i],dp[r][i]);
}
void QwQ() {
	n=rd(),fac[0]=1; for(int i=1;i<=n;i++) fac[i]=vmul(fac[i-1],i);
	for(int i=0;i<=n;i++) {C[i][0]=1; for(int j=1;j<=i;j++) C[i][j]=vadd(C[i-1][j-1],C[i-1][j]);}
	for(int l=1;l<=3;l++) for(int r=n-2;r<=n;r++) if(n+l-r<=3&&l<=r) sol(l,r);
	for(int i=1;i<=n;i++) f[i]=vmul(g[i],qpow(C[n][i],MOD-2)),cadd(ans,vmul(i,vsub(f[i],f[i-1])));
	wr(ans,"\n");
}
signed main() {
//	freopen("color.in","r",stdin),freopen("color.out","w",stdout);
	int T=1; while(T--) QwQ();
}


Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 39ms
memory: 103792kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 10
Accepted
time: 39ms
memory: 102480kb

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 10
Accepted
time: 47ms
memory: 102720kb

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

score: 10
Accepted
time: 42ms
memory: 102392kb

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

score: 10
Accepted
time: 48ms
memory: 105496kb

input:

100

output:

41620761

result:

ok 1 number(s): "41620761"

Test #6:

score: 10
Accepted
time: 45ms
memory: 107592kb

input:

200

output:

208771764

result:

ok 1 number(s): "208771764"

Test #7:

score: 10
Accepted
time: 51ms
memory: 112768kb

input:

500

output:

888621375

result:

ok 1 number(s): "888621375"

Test #8:

score: 10
Accepted
time: 385ms
memory: 196960kb

input:

4798

output:

319137015

result:

ok 1 number(s): "319137015"

Test #9:

score: 10
Accepted
time: 408ms
memory: 198560kb

input:

4999

output:

818467659

result:

ok 1 number(s): "818467659"

Test #10:

score: 10
Accepted
time: 396ms
memory: 199596kb

input:

5000

output:

142907477

result:

ok 1 number(s): "142907477"