QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#383689#6736. Alice and BobGordenGhost#TL 0ms0kbC++20889b2024-04-09 16:46:182024-04-09 16:46:18

Judging History

This is the latest submission verdict.

  • [2024-04-09 16:46:18]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2024-04-09 16:46:18]
  • Submitted

answer

#include"bits/stdc++.h"
#define endl '\n'
using ll=long long;
using namespace std;
constexpr int N=10000000+5,mod=998244353;
ll fact[N],inv[N];
ll qpow(ll a,ll b,ll p){
	a%=p;
	ll ans=1%p;
	for(;b;b>>=1){
		if(b&1)
			ans=ans*a%p;
		a=a*a%p;
	}
	return ans;
}
void init(){
	fact[0]=1;
	inv[0]=1;
	for(int i=1;i<N;i++)
		fact[i]=(i*fact[i-1])%mod;
	for(int i=1;i<N;i++)
		inv[i]=qpow(fact[i],mod-2,mod);
}
ll C(ll n,ll r){
	if(r>n||r<0)
		return 0;
	if(n==r||r==0)
		return 1;
	return (fact[n]*inv[r]%mod*inv[n-r]%mod);
}
void slove(){
	init();
	int n;
	cin>>n;
	ll ans=0;
	if(n==1){
		cout<<1<<endl;
		return;
	}
	for(int i=1;i<=n/2;i++){
		ans+=C(n-i,i-1)*fact[i-1]%mod*fact[n-i]%mod;
		ans%=mod;
	}
	cout<<ans<<endl;
}
signed main(){
	cin.tie(nullptr)->sync_with_stdio(0);
	int _=1;
//	cin>>_;
	while(_--){
		slove();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

1

output:


result: