QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408245#6736. Alice and BobTANGTANGCCTL 0ms0kbC++23927b2024-05-09 21:42:582024-05-09 21:42:59

Judging History

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

  • [2024-05-09 21:42:59]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-05-09 21:42:58]
  • 提交

answer

#include <bits/stdc++.h>
#include <sstream>

#define int long long
#define endl '\n'
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;

using namespace std;
const int MOD=998244353,N=1e7+50;
int fact[N],inv[N],fain[N];
int qmi(int a,int n) {
    int ans=1;
    while(n) {
        if(n&1) ans=(ans*a)%MOD;
        a=a*a%MOD;
        n>>=1;
    }
    return ans;
}
void init() {
    fact[0]=fact[1]=inv[0]=inv[1]=fain[0]=fain[1]=1;
    for (int i = 2; i <= 1e7+5; ++i) {
        fact[i]=(fact[i-1]*i)%MOD;
        inv[i]=qmi(i,MOD-2)%MOD;
        fain[i]=fain[i-1]*inv[i]%MOD;
    }
}
int A(int n,int m) {
    return fact[n]*fain[n-m]%MOD;
}
signed main() {
    IO;
    int n,ans=0;
    cin>>n;
    init();
    for (int i = 1; i <= n; ++i) {
        if(n-i<i-1) break;
        ans=(ans+A(n-i,i-1)*fact[n-i]%MOD)%MOD;
    }
    cout<<ans;
    return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

1

output:


result: