QOJ.ac

QOJ

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

Judging History

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

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

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 998244353;
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;
}

int main() {
    Init();
    int n; cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i - 1 <= n - i) {
            // ans = (ans + 1ll * fact[i - 1] * C(n - i, i - 1) % mod * fact[n - i] % mod) % mod;
            // ll res = 1;
            // for (int j = n - 2 * i + 2; j <= n - i; j++) res = res * j % mod;
            // cout << "range: " << n - 2 * i + 2 << ' ' << n - i << '\n';
            // ans = (ans + 1ll * fact[n - i] * res % mod) % mod;
            ans = (ans + 1ll * fact[n - i] * fact[n - i] % mod * infact[n - 2 * i + 1] % mod) % mod;
        }
    }
    cout << ans << '\n';

    return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

1

output:


result: