QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#412452#6736. Alice and BobXiaoretaW#TL 0ms0kbC++141.1kb2024-05-16 14:34:462024-05-16 14:34:47

Judging History

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

  • [2024-05-16 14:34:47]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-05-16 14:34:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 998244353;
namespace Comb{
const int N = 1e7 + 1;
int fact[N], infact[N];
int power(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) res = 1ll * res * a % mod;
        a = 1ll * a * a % mod;
        b >>= 1;
    }
    return res;
}
void Init() {
    fact[0] = 1;
    infact[0] = 1;
    for (int i = 1; i < N; i++) {
        fact[i] = 1ll * fact[i - 1] * i % mod;
        infact[i] = 1ll * infact[i - 1] * power(i, mod - 2) % mod;
    }
}
int C(int a, int b) {
    return 1ll * fact[a] * infact[b] % mod * infact[a - b] % mod;
}
}

using namespace Comb;
int main() {
    Init();
    int n; cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        // ll alice = 1ll * fact[i - 1] * fact[n - i] % mod;
        // ans = (ans + (fact[n - 1] - alice + mod) % mod) % mod;
        if (i - 1 <= n - i) {
            ans = (ans + 1ll * fact[i - 1] * C(n - i, i - 1) % mod  * fact[n - i] % mod) % mod;
        }
    }
    cout << ans << '\n';

    return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

1

output:


result: