QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#619570#8635. 圆zeq2021100 ✓341ms3864kbC++143.0kb2024-10-07 14:41:192024-10-07 14:41:19

Judging History

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

  • [2024-10-07 14:41:19]
  • 评测
  • 测评结果:100
  • 用时:341ms
  • 内存:3864kb
  • [2024-10-07 14:41:19]
  • 提交

answer

/*
*            /$$           /$$
*           |__/          |__/
*  /$$$$$$$$ /$$ /$$$$$$$$ /$$  /$$$$$$
* |____ /$$/| $$|____ /$$/| $$ /$$__  $$
*    /$$$$/ | $$   /$$$$/ | $$| $$  \ $$
*   /$$__/  | $$  /$$__/  | $$| $$  | $$
*  /$$$$$$$$| $$ /$$$$$$$$| $$|  $$$$$$$
* |________/|__/|________/|__/ \____  $$
*                                   | $$
*                                   | $$
*                                   |__/
*/
//hj23308保佑我
//Missile保佑我
/*
* 醒了在梦里挣扎,不觉黯淡了朝霞
*/
/*
* 我很高兴你没有忘了我,但是我现在更希望你已经忘了我了。
* 希望在你的记忆中,我只是尘土一撮,从你的全世界路过,然后四散飞扬不留下一点痕迹,而你要不回头的往前走。
* 我更希望我只是从你的全世界路过,只是路过
*/
/*
* 只是我在十字路口守了太久,守到黄沙如雨掩埋一切痕迹,才发现自己等的人已经离开了。
*/
/*
* 听我的 别回头 回头就可能会泪流满面,会被黄沙掩埋,所以即使痛苦也要向前走
*/
/*
* 我听到了「天行健」的回响,这是一个伟大斗士的不息自强;
* 我听到了「破万法」的回响,这是一个黑道打手的守护欲望;
* 我看见了「生生不息」的激荡,这是一个骗子的伟大乐章!
*/
/*
* 我用虚假的面具照顾着细腻的感情;
* 我以华丽的衣物下藏着腐烂的血肉;
* 当我摘下面具,褪去衣物,即便是我最亲近的人,也无法直视我
*/
#include<bits/stdc++.h>
using namespace std;
const int MOD=998244353;
const int MAXN=5e3+5;
int n;
long long fac[MAXN];
int f[MAXN][2][2],g[MAXN][2][2];
long long qpow(long long u,long long k)
{
	long long Ans=1;
	while(k) {
		if(k&1) Ans=Ans*u%MOD;
		u=u*u%MOD;
		k/=2;
	}
	return Ans;
}
long long inv(long long u)
{
	return qpow(u,MOD-2);
}
long long A(int N,int M)
{
	return fac[M]*inv(fac[M-N])%MOD;
}
long long solve()
{
	fac[0]=1;
	for(int i=1;i<=n;i++) {
		fac[i]=fac[i-1]*i%MOD;
	}
	long long Ans=0;
	for(int c0=0;c0<=1;c0++) {
		for(int c1=0;c1<=1;c1++) {
			memset(f,0,sizeof(f));
			f[c0+c1][c0][c1]=1;
			for(int site=3;site<=n-1;site++) {
				memcpy(g,f,sizeof(f));
				memset(f,0,sizeof(f));
				for(int i=0;i<site;i++) {
					for(int cA=0;cA<=1;cA++) {
						for(int cB=0;cB<=1;cB++) {
							for(int cC=0;cC<=1;cC++) {
								if(cA+cB+cC==0) continue;
								f[i+cC][cB][cC]=(f[i+cC][cB][cC]+g[i][cA][cB])%MOD;
							}
						}
					}
				}
			}
			for(int i=0;i<=n;i++) {
				long long sum=0;
				for(int cA=0;cA<=1;cA++) {
					for(int cB=0;cB<=1;cB++) {
						if(c0&&(cA||cB)) continue;
						if(cB&&(c0||c1)) continue;
						sum=(sum+f[i][cA][cB])%MOD;
					}
				}
				Ans=(Ans+n*sum%MOD*A(i,i)%MOD*(i+1)%MOD*inv(A(i+1,n))%MOD)%MOD;
			}
		}
	}
	return Ans;
}
int main()
{
//	freopen("color.in","r",stdin);
//	freopen("color.out","w",stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n;
	cout<<solve()<<"\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

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

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

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

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

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

input:

100

output:

41620761

result:

ok 1 number(s): "41620761"

Test #6:

score: 10
Accepted
time: 3ms
memory: 3812kb

input:

200

output:

208771764

result:

ok 1 number(s): "208771764"

Test #7:

score: 10
Accepted
time: 10ms
memory: 3744kb

input:

500

output:

888621375

result:

ok 1 number(s): "888621375"

Test #8:

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

input:

4798

output:

319137015

result:

ok 1 number(s): "319137015"

Test #9:

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

input:

4999

output:

818467659

result:

ok 1 number(s): "818467659"

Test #10:

score: 10
Accepted
time: 341ms
memory: 3760kb

input:

5000

output:

142907477

result:

ok 1 number(s): "142907477"