QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#505766#8635. 圆LGMaster100 ✓55ms199300kbC++141.2kb2024-08-05 10:57:162024-08-05 10:57:17

Judging History

你现在查看的是最新测评结果

  • [2024-08-05 10:57:17]
  • 评测
  • 测评结果:100
  • 用时:55ms
  • 内存:199300kb
  • [2024-08-05 10:57:16]
  • 提交

answer

#include<bits/stdc++.h>
#define lint long long
using namespace std;
inline lint read(){
    char c; lint f=1,res=0;
    while(c=getchar(),!isdigit(c)) if(c=='-') f*=-1;
    while(isdigit(c)) res=res*10+c-'0',c=getchar();
    return res*f;
}
void write(int x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    static int sta[35];
    int top=0;
    do{
        sta[top++]=x%10,x/=10;
    }while(x);
    while(top)putchar(sta[--top]+'0');
}
const int N=5005,mod=998244353;
lint n,f[N][N],fac[N],ans;
inline lint ksm(lint a,lint b){
	lint res=1;
	while(b){
		if(b&1) res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
inline bool check(){
	return n<=3;
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    n=read();
    if(check()) puts("1"),exit(0);
    f[1][1]=fac[1]=1;
    for(int i=2;i<=n;i++){
    	fac[i]=(fac[i-1]*i)%mod;
    	for(int j=1;j<=n;j++){
    		f[i][j]=(f[i-1][j-1]+f[i-2][j-1])%mod;
    		if(i>=4) f[i][j]=(f[i][j]+f[i-3][j-1])%mod;
		}
	}
	for(int i=1;i<=n;i++) ans=(ans+((f[n-3][i-1]*2+f[n-4][i-1]+f[n-2][i])%mod)*i%mod*fac[i-1]%mod*fac[n-i]%mod)%mod;
	int inv=ksm(fac[n-1],mod-2);
	printf("%lld",ans*inv%mod);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 0ms
memory: 3528kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 10
Accepted
time: 0ms
memory: 3776kb

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 10
Accepted
time: 0ms
memory: 3932kb

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

score: 10
Accepted
time: 1ms
memory: 5764kb

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

score: 10
Accepted
time: 1ms
memory: 8000kb

input:

100

output:

41620761

result:

ok 1 number(s): "41620761"

Test #6:

score: 10
Accepted
time: 0ms
memory: 12124kb

input:

200

output:

208771764

result:

ok 1 number(s): "208771764"

Test #7:

score: 10
Accepted
time: 2ms
memory: 22556kb

input:

500

output:

888621375

result:

ok 1 number(s): "888621375"

Test #8:

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

input:

4798

output:

319137015

result:

ok 1 number(s): "319137015"

Test #9:

score: 10
Accepted
time: 55ms
memory: 199300kb

input:

4999

output:

818467659

result:

ok 1 number(s): "818467659"

Test #10:

score: 10
Accepted
time: 44ms
memory: 199228kb

input:

5000

output:

142907477

result:

ok 1 number(s): "142907477"