QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#399346#6736. Alice and BobKidding_MaWA 86ms159912kbC++141.1kb2024-04-26 10:58:082024-04-26 10:58:09

Judging History

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

  • [2024-04-26 10:58:09]
  • 评测
  • 测评结果:WA
  • 用时:86ms
  • 内存:159912kb
  • [2024-04-26 10:58:08]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

constexpr int P = 998244353;
i64 *fac, *ifac;

i64 power(i64 a, i64 b, int p = P) {
    i64 res = 1;
    for (; b; b >>= 1, a = a * a % p) {
        if (b & 1) {
            res = res * a % p;
        }
    }
    return res;
}
   
i64 inv(i64 x) {
    return power(x, P - 2, P);
}
  
void init(int N) {
    fac = new i64 [N + 1];
    ifac = new i64 [N + 1];
    fac[0] = 1;
    for (int i = 1; i <= N; i++) {
        fac[i] = fac[i - 1] * i % P;
    }
    ifac[N] = inv(fac[N]);
    for (int i = N - 1; i >= 0; i--) {
        ifac[i] = ifac[i + 1] * (i + 1) % P;
    }
}
  
i64 C(int n, int m) {
    if (m < 0 || m > n || n < 0) {
        return 0;
    }
    return fac[n] * ifac[m] % P * ifac[n - m] % P;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    init(1E7);

    int n;
    cin >> n;
    i64 ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = (ans + C(n - i, i - 1) * C(n - i, n - i) % P) % P;
    }
    cout << ans << '\n';

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 83ms
memory: 159912kb

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 83ms
memory: 159828kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: -100
Wrong Answer
time: 86ms
memory: 159896kb

input:

10

output:

55

result:

wrong answer 1st numbers differ - expected: '997920', found: '55'