QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#81890#2834. NonsenseAHSFNU_team_0#WA 7ms3552kbC++143.1kb2023-02-26 17:20:422023-02-26 17:20:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-26 17:20:46]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3552kb
  • [2023-02-26 17:20:42]
  • 提交

answer


#include <bits/stdc++.h>

using namespace std; const int maxn = 5e3 + 5, mod = 998244353; typedef long long ll;

inline int qpow(int x, int k) { int res = 1; while (k) { if (k & 1) res = (ll)res * x % mod; x = (ll)x * x % mod, k >>= 1; } return res; }

int n, A, B, q, a[maxn], b[maxn], ma, mb;

int C[maxn << 1], F1[maxn << 1], F2[maxn], C_[maxn << 1];

// inline int Calc(int a, int b, int i)
// {
//     return (ll)F2[i] * qpow(F2[a], )
// }

int f[maxn][maxn];

int main()
{
    for (int i = F2[0] = 1; i < maxn; i++) F2[i] = (ll)F2[i - 1] * i % mod;
    while (~scanf("%d%d%d%d", &n, &A, &B, &q))
    {
        ma = mb = 0;
        for (int i = 1; i <= q; i++) scanf("%d%d", a + i, b + i), ma = max(ma, a[i]), mb = max(mb, b[i]);
        for (int i = C[0] = 1; i <= ma + mb; i++) C[i] = (ll)C[i - 1] * (n - i + 1) % mod * qpow(i, mod - 2) % mod;
        for (int i = C_[0] = 1; i <= ma + mb; i++) C_[i] = (ll)C_[i - 1] * (n - i + 2) % mod * qpow(i, mod - 2) % mod;
        for (int i = 0; i <= ma + mb; i++) cerr << C[i] << ' '; cerr << endl;
        if (A == 0 && B != 0)
        {
            F1[0] = n;
            for (int i = 1; i <= ma + mb; i++) F1[i] = (ll)F1[i - 1] * (n - i) % mod;
            for (int i = 1; i <= q; i++)
            {
                int Ans = (ll)F1[a[i] + b[i] - 1] * qpow(F1[a[i] - 1], mod - 2) % mod * qpow(F2[b[i]], mod - 2) % mod * qpow(B, n - a[i] - a[i]) % mod;
                printf("%d\n", (Ans + mod) % mod);
            }
            continue;
        }
        if (A != 0 && B == 0)
        {
            F1[0] = n;
            for (int i = 1; i <= ma + mb; i++) F1[i] = (ll)F1[i - 1] * (n - i) % mod;
            for (int i = 1; i <= q; i++)
            {
                int Ans = (ll)F1[a[i] + b[i] - 1] * qpow(F1[b[i] - 1], mod - 2) % mod * qpow(F2[a[i]], mod - 2) % mod * qpow(A, n - a[i] - b[i]) % mod;
                printf("%d\n", (Ans + mod) % mod);
            }
            continue;
        }
        if (A == 0 && B == 0)
        {
            for (int i = 1; i <= q; i++) puts("0");
            continue;
        }
        if (A == B)
        {
            for (int i = 1; i <= q; i++)
            {
                int Ans = (ll)qpow(A, n - a[i] - b[i]) * C[a[i] + b[i]] % mod;
                printf("%d\n", (Ans + mod) % mod);
            }
            continue;
        }
        for (int i = 0; i <= ma; i++) for (int j = 0; j <= mb; j++) f[i][j] = 0;
        for (int j = 0, K = qpow(B, n + 1); j <= mb; j++) f[0][j] = (ll)C_[j] * K % mod;
        for (int i = 0, K = qpow(A, n + 1); i <= ma; i++) f[i][0] = (f[i][0] - (ll)C_[i] * K) % mod;
        int K = qpow(B - A, mod - 2);
        for (int i = 0; i <= ma; i++) for (int j = 0; j <= mb; j++)
        {
            f[i][j] = (f[i][j] - (ll)B * (j ? f[i][j - 1] : 0) + (ll)A * (i ? f[i - 1][j] : 0)) % mod * K % mod;
        }
        for (int i = 1; i <= q; i++)
        {
            // int Ans = f[a[i]][b[i]];
            int Ans = (ll)f[a[i]][b[i]] * qpow((ll)qpow(A, a[i]) * qpow(B, b[i]) % mod, mod - 2) % mod;
            printf("%d\n", (Ans + mod) % mod);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

input:

3 1 2 2
1 1
1 2
100 2 3 1
1 1

output:

6
1
866021789

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 7ms
memory: 3532kb

input:

1000000000 0 1 1
1000 1000
2 0 0 1
1 1
2 998244352 998244352 1
1 1

output:

381781645
0
1

result:

wrong answer 2nd lines differ - expected: '1', found: '0'