QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#619870#8635. 圆Y204335100 ✓46ms199296kbC++14996b2024-10-07 15:43:002024-10-07 15:43:00

Judging History

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

  • [2024-10-07 15:43:00]
  • 评测
  • 测评结果:100
  • 用时:46ms
  • 内存:199296kb
  • [2024-10-07 15:43:00]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=5010,mod=998244353;
int n;
ll jc[N],dp[N][N],f[N],ans;
ll mi(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
void init(){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cin>>n;
	jc[0]=1;
	for(int i=1;i<=n;i++)jc[i]=jc[i-1]*i%mod;
}
int main(){
	init();
	if(n==3){
		cout<<1;
		return 0;
	}
	if(n==4){
		cout<<2;
		return 0;
	}
	n--;
	dp[1][1]=dp[1][2]=dp[1][3]=1;
	for(int i=2;i<=n-1;i++){
		for(int j=1;j<=n-1;j++){
			dp[i][j]=dp[i-1][j-1]+dp[i-1][j-2];
			if(j>=3)dp[i][j]+=dp[i-1][j-3];
			dp[i][j]%=mod;
		}
	}
	for(int i=1;i<=n;i++){
		f[i]=dp[i][n-1]+dp[i][n-2]+dp[i-1][n-1]+dp[i-1][n-2]+dp[i-1][n-3];
		f[i]%=mod;
	}
	ans=0;
	for(int i=1;i<=n;i++){
		ans+=(f[i]*jc[i]%mod*jc[n-i]%mod+mod-f[i-1]*jc[i-1]%mod*jc[n-(i-1)]%mod)*i%mod;
		ans%=mod;
	}
	ans=ans*mi(jc[n],mod-2)%mod;
	cout<<(ans+1)%mod;
	return 0;
} 

详细


Pretests


Final Tests

Test #1:

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

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

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

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

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

input:

100

output:

41620761

result:

ok 1 number(s): "41620761"

Test #6:

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

input:

200

output:

208771764

result:

ok 1 number(s): "208771764"

Test #7:

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

input:

500

output:

888621375

result:

ok 1 number(s): "888621375"

Test #8:

score: 10
Accepted
time: 32ms
memory: 192708kb

input:

4798

output:

319137015

result:

ok 1 number(s): "319137015"

Test #9:

score: 10
Accepted
time: 36ms
memory: 199224kb

input:

4999

output:

818467659

result:

ok 1 number(s): "818467659"

Test #10:

score: 10
Accepted
time: 46ms
memory: 199296kb

input:

5000

output:

142907477

result:

ok 1 number(s): "142907477"