QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#591543#8635. 圆wanggk40 2ms3948kbC++141.9kb2024-09-26 16:21:202024-09-26 16:21:21

Judging History

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

  • [2024-09-26 16:21:21]
  • 评测
  • 测评结果:40
  • 用时:2ms
  • 内存:3948kb
  • [2024-09-26 16:21:20]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,il,ir) for(register int i=(il);i<=(ir);++i)
#define Forr(i,ir,il) for(register int i=(ir);i>=(il);--i)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<typename T>
inline void read(T& x){
	bool f=0;x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){ if(ch=='-') f=1; ch=getchar(); }
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	if(f) x=-x;
}
template<typename T,typename... Args>
void read(T& first,Args&... args){ read(first),read(args...); }
const ll mod=998244353;
const int maxn=5005;
namespace stO_Orz{
	int n;
	ll ans=0,sum=0;
	bool vis[maxn];
	int black[maxn];
//	ll f[5005][5005];
	ll qp(ll x,ll base){
		ll res=1ll;
		while(base){
			if(base&1) res=res*x%mod;
			x=x*x%mod,base>>=1;
		}return res;
	}
	ll dfs()
	{
		bool flag=1;
		for(int i=0;i<n&&flag;++i) if(!black[i]) flag=0;
		if(flag) return 0;
		
		ll res=0,sum=0;
		for(int i=0;i<n;++i) if(!vis[i])
		{
			vis[i]=1;
			for(int j=i-1;j<=i+1;++j) ++black[(j+n)%n];
			
			res+=(1+dfs()),sum++;
			for(int j=i-1;j<=i+1;++j) --black[(j+n)%n];
			vis[i]=0;
		}
//		For(i,0,n-1) cout<<black[i]<<' ';cout<<endl;
//		cout<<res*qp(sum,mod-2ll)%mod<<endl;
		return res*qp(sum,mod-2ll)%mod;
	}
	signed my_main()
	{
		read(n);
		vis[0]=1,black[0]=black[n-1]=black[1]=1;
//		dfs(1);
		/*f[1][3]=1;
		For(i,1,n)
			For(j,1,n) 
			{
				if(j-i>2&&j!=n) f[i][j]=(f[i][j]+f[i-1][j])%mod;
				if(j) f[i][j]=(f[i][j]+f[i-1][j-1])%mod;
				if(j>=2) f[i][j]=(f[i][j]+f[i-1][j-2])%mod;
				if(j>=3) f[i][j]=(f[i][j]+f[i-1][j-3])%mod;
			}
		ll ans=0,sum=0;
		For(i,1,n) ans=(ans+(f[i][n]*(ll)i%mod))%mod;
		For(i,1,n) sum=(sum+f[i][n])%mod;*/
//		printf("%lld %lld\n",ans,sum);
//		sum=qp(sum,mod-2ll);
//		ans=ans*sum%mod;
		printf("%lld\n",(dfs()+1)%mod);
		return 0;
	}
}
signed main(){ return stO_Orz::my_main(); }

详细


Pretests


Final Tests

Test #1:

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

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

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

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: