QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#852193#9995. 乒乓球赛CelebrateWA 3ms5152kbC++142.7kb2025-01-11 10:35:432025-01-11 10:35:45

Judging History

This is the latest submission verdict.

  • [2025-01-11 10:35:45]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 5152kb
  • [2025-01-11 10:35:43]
  • Submitted

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N = 1e5 + 10, mod = 998244353;

int power(int a, int b) {
    int ret = 1;
    while (b) {
        if (b & 1) {
            ret = 1ll * ret * a % mod;
        }
        a = 1ll * a * a % mod; b >>= 1;
    }
    return ret;
}
int n, a[N], b[N];
int fc[N << 1], ifc[N << 1];

int C(int a, int b) {
    if (a < 0 || b < 0 || a < b) {
        return 0;
    }
    return 1ll * fc[a] * ifc[b] % mod * ifc[a - b] % mod;
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        if (a[i] < b[i]) {
            swap(a[i], b[i]);
        }
        if (a[i] != -1 && a[i] + b[i] != i) {
            cout << "0\n"; return;
        }
    }
    if (11 <= n && n <= 20) {
        if (a[n] != -1 && (a[n] != 11 || b[n] != n - 11)) {
            cout << "0\n"; return;
        }
        else {
            a[n] = 11, b[n] = n - 11;
        }
        if (a[n - 1] != -1 && (a[n - 1] != 10 || b[n - 1] != n - 11)) {
            cout << "0\n"; return;
        }
        else {
            a[n - 1] = 10, b[n - 1] = n - 11;
        }
    }
    else if (n > 20 && n % 2 == 0) {
        if (a[n] != -1 && (a[n] != (n - 2) / 2 + 2 || b[n] != (n - 2) / 2)) {
            cout << "0\n"; return;
        }
        else {
            a[n] = (n - 2) / 2 + 2, b[n] = (n - 2) / 2;
        }
        for (int i = 20; i < n; i ++) {
            int x = i / 2, y = i / 2;
            if (i & 1) x++;
            if (a[i] != -1 && (a[i] != x || b[i] != y)) {
                cout << "0\n"; return;
            }
            else {
                a[i] = x, b[i] = y;
            }
        }
    }
    else {
        cout << "0\n"; return;
    }
    int last = 0, lasta = 0, lastb = 0;
    int ans = 1;
    for (int i = 1; i <= n; i++) {
        if (a[i] == -1) {
            continue;
        }
        int s1 = C(i - last, a[i] - lasta);
        int s2 = C(i - last, a[i] - lastb);
        if (a[i] == b[i]) {
            ans = 1ll * ans * s1 % mod;
        }
        else {
            ans = 1ll * ans * (s1 + s2) % mod;
        }
        last = i, lasta = a[i], lastb = b[i];
    }
    cout << ans << endl;
}

int main() {
    // freopen("in.in", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    fc[0] = 1;
    for (int i = 1; i <= 200000; i++) {
        fc[i] = 1ll * fc[i - 1] * i % mod;
    }
    ifc[200000] = power(fc[200000], mod - 2);
    for (int i = 199999; i >= 0; i--) {
        ifc[i] = 1ll * ifc[i + 1] * (i + 1) % mod;
    }

    int T; cin >> T;
    while (T--) {
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 5152kb

input:

7
11
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
11
-1 -1
1 1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
11
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
1 11
22
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-...

output:

2
0
0
0
369512
0
864

result:

ok 7 lines

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 5152kb

input:

12
10
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
11
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
12
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
12
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
11 0
-1 -1
12
-1 -1
-1 -1
-...

output:

0
2
22
0
0
0
0
0
0
0
0
0

result:

wrong answer 8th lines differ - expected: '369512', found: '0'