QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#619483#8635. 圆LinkWish100 ✓294ms395128kbC++142.1kb2024-10-07 14:22:092024-10-07 14:22:09

Judging History

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

  • [2024-10-07 14:22:09]
  • 评测
  • 测评结果:100
  • 用时:294ms
  • 内存:395128kb
  • [2024-10-07 14:22:09]
  • 提交

answer

//Linkwish's code
#include<bits/stdc++.h>
#define endl '\n'
#define si inline
#define fi first
#define se second
using namespace std;
typedef long long ll;typedef __int128 li;typedef long double ld;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef const int ci;typedef const ll cl;ci iinf=INT_MAX;cl linf=LLONG_MAX;
template<typename T>si bool gmax(T &x,const T y){if(x<y)return x=y,1;return 0;}
template<typename T>si bool gmin(T &x,const T y){if(y<x)return x=y,1;return 0;}

namespace LinkWish{

	ci N=5005,mod=998244353;

	si int qpow(int x,int y){
		int res=1;
		for(;y;x=1ll*x*x%mod,y>>=1)if(y&1)res=1ll*res*x%mod;
		return res;
	}

	int n;
	int f[N][N][3];
	int g[N][N];

	int fac[N];

	si void dp(int L,int R,int &x){
		memset(f,0,sizeof f),memset(g,0,sizeof g);
		x=1;
		for(int i=L;i<R;i++){
			for(int j=0;j<=i+1;j++){
				(f[i+1][j][0]+=f[i][j][1])%=mod;
				(f[i+1][j][2]+=f[i][j][0])%=mod;
				(f[i+1][j+1][1]+=1ll*(1ll*f[i][j][0]+f[i][j][1]+f[i][j][2])%mod)%=mod;
				
				(g[i+1][j]+=(f[i][j][2]+g[i][j])%mod)%=mod;
				(g[i+1][j+1]+=g[i][j])%=mod;
			}
		}
	}
	
	void mian(){
		cin>>n;

		fac[0]=1;for(int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
		
		int ans=0;

		//不选 n
		//选 1
		dp(2,n,f[2][1][1]);
		for(int i=0,p=1;i<=n;p=1ll*p*(n-(i++))%mod){
			int ip=qpow(p,mod-2)%mod;
			(g[n][i]+=f[n][i][2])%=mod;
			(ans+=1ll*g[n][i]*fac[i]%mod*ip%mod)%=mod;
		}

		//不选 1
		f[2][0][2]=1;
		dp(2,n,f[2][0][2]);
		for(int i=0,p=1;i<=n;p=1ll*p*(n-(i++))%mod){
			int ip=qpow(p,mod-2)%mod;
			(g[n][i]+=(f[n][i][0]+f[n][i][2])%mod)%=mod;
			(ans+=1ll*g[n][i]*fac[i]%mod*ip%mod)%=mod;
		}

		//选 n
		dp(1,n,f[1][1][1]);
		for(int i=0,p=1;i<=n;p=1ll*p*(n-(i++))%mod){
			int ip=qpow(p,mod-2)%mod;
			(ans+=1ll*g[n][i]*fac[i]%mod*ip%mod)%=mod;
		}

		cout<<ans<<endl;
	}
}

signed main(){
	#ifndef ONLINE_JUDGE
	assert(freopen("color.in","r",stdin));
	assert(freopen("color.out","w",stdout));
	#endif
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	LinkWish::mian();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 95ms
memory: 394976kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 10
Accepted
time: 86ms
memory: 394980kb

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 10
Accepted
time: 75ms
memory: 395104kb

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

score: 10
Accepted
time: 67ms
memory: 395048kb

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

score: 10
Accepted
time: 75ms
memory: 395044kb

input:

100

output:

41620761

result:

ok 1 number(s): "41620761"

Test #6:

score: 10
Accepted
time: 76ms
memory: 395100kb

input:

200

output:

208771764

result:

ok 1 number(s): "208771764"

Test #7:

score: 10
Accepted
time: 86ms
memory: 394980kb

input:

500

output:

888621375

result:

ok 1 number(s): "888621375"

Test #8:

score: 10
Accepted
time: 268ms
memory: 395068kb

input:

4798

output:

319137015

result:

ok 1 number(s): "319137015"

Test #9:

score: 10
Accepted
time: 291ms
memory: 395116kb

input:

4999

output:

818467659

result:

ok 1 number(s): "818467659"

Test #10:

score: 10
Accepted
time: 294ms
memory: 395128kb

input:

5000

output:

142907477

result:

ok 1 number(s): "142907477"