QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591650#8635. 圆jianhe40 2ms3728kbC++141.1kb2024-09-26 17:01:532024-09-26 17:01:53

Judging History

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

  • [2024-09-26 17:01:53]
  • 评测
  • 测评结果:40
  • 用时:2ms
  • 内存:3728kb
  • [2024-09-26 17:01:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=998244353,N=5050; 
ll n,ans,ct,jc[N],col[N];
bool vis[N];
ll ksm(ll a,ll b){
	ll ct=1;
	while(b){
		if(b&1) ct=ct*a%mod;
		b>>=1,a=a*a%mod;
	}
	return ct;
}
//void init(){jc[0]=1;for(int i=1;i<=n;i++) jc[i]=jc[i-1]*i%mod;}
//ll A(ll n,ll m){return jc[n]*ksm(jc[n-m],mod-2)%mod;}
ll lt(ll i){if(i==1) return n;return i-1;}
ll nt(ll i){if(i==n) return 1;return i+1;}
ll dfs(ll s){
	if(s>=n) return 0;
	ll res=0,ct=0;
	for(int i=1;i<=n;i++)
		if(vis[i]==0){
			ll t=(col[i]==0)+(col[lt(i)]==0)+(col[nt(i)]==0);
			vis[i]=1,col[lt(i)]++,col[nt(i)]++,col[i]++;
			res+=dfs(s+t)+1,ct++;
			vis[i]=0;col[lt(i)]--,col[nt(i)]--,col[i]--;
		}
	return res*ksm(ct,mod-2)%mod;
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n;//init();
//	for(int x=2;x<=n-2;x++) ans+=(A(n-1,x-1)-A(n-2,x-2)*(x-1))%mod*x%mod,ct+=(A(n-1,x-1)-A(n-2,x-2)*(x-1))%mod,cout<<ct<<"\n";
//	ans%=mod,ct%=mod;
//	ans=ans*ksm(ct,mod-2)%mod;
//	cout<<ans;
	vis[1]=1;col[1]=col[2]=col[n]=1;
	cout<<(dfs(3)+1)%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: 3660kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

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

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

score: 0
Time Limit Exceeded

input:

100

output:


result:


Test #6:

score: 0
Time Limit Exceeded

input:

200

output:


result:


Test #7:

score: 0
Time Limit Exceeded

input:

500

output:


result:


Test #8:

score: 0
Time Limit Exceeded

input:

4798

output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

4999

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

5000

output:


result: