QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#383689 | #6736. Alice and Bob | GordenGhost# | TL | 0ms | 0kb | C++20 | 889b | 2024-04-09 16:46:18 | 2024-04-09 16:46:18 |
Judging History
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