QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#854176#9995. 乒乓球赛samneverWA 21ms5836kbC++232.8kb2025-01-11 22:12:152025-01-11 22:12:15

Judging History

This is the latest submission verdict.

  • [2025-01-11 22:12:15]
  • Judged
  • Verdict: WA
  • Time: 21ms
  • Memory: 5836kb
  • [2025-01-11 22:12:15]
  • Submitted

answer

#include<cstdio>
#include<ctime>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<numeric>
#include<functional>
#define fs(i,x,y) for(int i=(x),_=(y);i<=_;++i)
#define fn(i,x,y) for(int i=(x),_=(y);i>=_;--i)
#define tor(i,v,x) for(int i=head[x],v=to[i];i;i=nxt[i],v=to[i])
#define ls(x) ch[x][0]
#define rs(x) ch[x][1]
#define mpi(x,y) make_pair(x,y)
#define pi pair<int,int>
#define fi first
#define se second
// #define int ll
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
template<typename T>
void read(T& x) {
    x = 0; char ch = getchar(); bool f = 0;
    while (ch < '0' || ch > '9') {
        if (ch == '-')f = 1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
    x = f ? -x : x;
}
template<typename T, typename...Args>
void read(T& x, Args &...args) {
    read(x); read(args...);
}

const int N = 1e6 + 7, P = 998244353;
int n, m;
int a[N], b[N];
int dp[21][21];
bool ban[21][21];

void solve() {
    read(n);
    bool ok = true;
    fs(i, 1, n) {
        read(a[i], b[i]);
        if (a[i] == -1)continue;
        if (a[i] + b[i] != i)ok = false;
        if (i < n) {
            if (i <= 20) {
                if (max(a[i], b[i]) >= 11)ok = false;
            } else {
                if (abs(a[i] - b[i]) >= 2)ok = false;
            }
        } else {
            if (i <= 20) {
                if (max(a[i], b[i]) != 11)ok = false;
            } else {
                if (abs(a[i] - b[i]) != 2)ok = false;
            }
        }
    }
    if (!ok) {
        printf("0\n");
        return;
    }
    fs(i, 0, 20)fs(j, 0, 20)ban[i][j] = false, dp[i][j] = 0;
    fs(i, 1, 20) {
        if (a[i] >= 0) {
            fs(j, 0, i)ban[j][i - j] = true;
            ban[a[i]][b[i]] = ban[b[i]][a[i]] = false;
        }
    }
    dp[0][0] = 1;
    ban[0][0] = true;
    fs(i, 0, 10) {
        fs(j, 0, 10) {
            if (ban[i][j])continue;
            if (j > 0)dp[i][j] = (dp[i][j] + dp[i][j - 1]) % P;
            if (i > 0)dp[i][j] = (dp[i][j] + dp[i - 1][j]) % P;
        }
    }
    if (n > 20) {
        if (n % 2) {
            printf("0\n");
        } else {
            int ans = dp[10][10];
            fs(i, 21, n - 1) {
                if ((i % 2))ans = ans * 2 % P;
            }
            printf("%d\n", ans);
        }
    } else {
        if (n < 11) {
            printf("0\n");
        } else {
            printf("%d\n", (dp[10][n - 11] + dp[n - 11][10]) % P);
        }
    }
}
signed main() {
    int T;
    read(T);
    while (T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5784kb

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: 0
Accepted
time: 1ms
memory: 5772kb

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
369512
0
0
0
0

result:

ok 12 lines

Test #3:

score: 0
Accepted
time: 17ms
memory: 5836kb

input:

20000
16
-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
-1 -1
2
-1 -1
-1 -1
25
-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
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
13
-1 -1
-1 -1
-1 -1
-1 -1
-...

output:

6006
0
0
132
0
0
2002
0
0
0
0
369512
184756
0
0
0
0
41756
572
0
2
2002
2
0
6006
0
0
38896
369512
87516
369512
0
6006
0
0
6006
0
369512
0
0
369512
572
184756
0
739024
87516
145860
2
0
16016
0
2002
6006
0
0
0
0
0
132
6006
572
2002
0
3520
0
0
0
0
22
0
2
184756
0
0
0
0
0
0
0
0
0
572
3432
572
132
3960
57...

result:

ok 20000 lines

Test #4:

score: 0
Accepted
time: 21ms
memory: 5724kb

input:

20000
25
-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
-1 -1
-1 -1
-1 -1
-1 -1
6 14
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
2
-1 -1
-1 -1
9
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
3 4
-1 -1
-1 -1
5
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
15
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 ...

output:

0
0
0
0
2002
0
1350
87516
87516
0
132
132
0
0
38896
0
31680
0
572
132
0
184756
38896
42
38896
184756
572
6006
38896
369512
0
0
0
252
0
0
0
739024
87516
0
0
0
132
0
0
132
132
22
0
132
0
87516
0
0
0
739024
132
16016
0
0
0
0
0
22
0
22
0
0
0
2002
0
2002
0
369512
22
22
38896
38896
87516
0
0
0
0
0
0
2
252...

result:

ok 20000 lines

Test #5:

score: 0
Accepted
time: 15ms
memory: 5780kb

input:

20000
10
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
25
-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
8 8
-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
25
-1...

output:

0
0
22
0
43472
6006
0
132
0
0
180
16016
6006
0
0
0
0
0
0
0
0
38896
22
0
2
0
0
422
8008
0
0
0
739024
0
0
0
0
0
38896
132
572
0
0
0
0
210
132
0
0
369512
6006
2002
22
0
0
0
2002
184756
87516
0
0
0
132
0
2
22
0
0
0
6006
0
184756
0
4
0
0
0
132
0
22
1456
366080
0
14256
184756
6006
0
0
0
0
0
0
10010
0
0
0
...

result:

ok 20000 lines

Test #6:

score: -100
Wrong Answer
time: 18ms
memory: 5740kb

input:

20000
21
-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
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
6
-1 -1
-1 -1
-1 -1
-1 -1
0 5
-1 -1
2
-1 -1
-1 -1
10
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
7
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
9
-1 -1
...

output:

0
0
0
0
0
0
0
16016
40
22
0
0
0
0
87516
2002
0
2002
0
739024
0
739024
369512
0
87516
0
0
64
0
0
0
422
0
0
572
0
980
22
22
0
0
0
160
0
0
0
0
0
739024
0
0
0
22
6006
0
0
0
72
0
0
0
0
0
0
0
0
0
0
0
22
0
0
0
0
0
22
0
0
132
0
0
0
0
20
0
2970
0
0
0
0
0
0
0
0
0
2
0
0
45760
572
0
0
0
0
0
0
0
0
184756
0
0
0
8...

result:

wrong answer 19434th lines differ - expected: '6600', found: '9900'