QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#846681#9995. 乒乓球赛caijianhongAC ✓84ms3716kbC++232.5kb2025-01-07 12:08:442025-01-07 12:08:45

Judging History

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

  • [2025-01-07 12:08:45]
  • 评测
  • 测评结果:AC
  • 用时:84ms
  • 内存:3716kb
  • [2025-01-07 12:08:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) fprintf(stderr, ##__VA_ARGS__)
#else
#define endl "\n"
#define debug(...) void(0)
#endif
using LL = long long;
template <unsigned umod>
struct modint {/*{{{*/
  static constexpr int mod = umod;
  unsigned v;
  modint() = default;
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
    modint(const T& y) : v((unsigned)(y % mod + (is_signed<T>() && y < 0 ? mod : 0))) {}
  modint& operator+=(const modint& rhs) { v += rhs.v; if (v >= umod) v -= umod; return *this; }
  modint& operator-=(const modint& rhs) { v -= rhs.v; if (v >= umod) v += umod; return *this; }
  modint& operator*=(const modint& rhs) { v = (unsigned)(1ull * v * rhs.v % umod); return *this; }
  modint& operator/=(const modint& rhs) { assert(rhs.v); return *this *= qpow(rhs, mod - 2); }
  friend modint operator+(modint lhs, const modint& rhs) { return lhs += rhs; }
  friend modint operator-(modint lhs, const modint& rhs) { return lhs -= rhs; }
  friend modint operator*(modint lhs, const modint& rhs) { return lhs *= rhs; }
  friend modint operator/(modint lhs, const modint& rhs) { return lhs /= rhs; }
  template <class T> friend modint qpow(modint a, T b) {
    modint r = 1;
    for (assert(b >= 0); b; b >>= 1, a *= a) if (b & 1) r *= a;
    return r;
  }
  friend int raw(const modint& self) { return self.v; }
  friend ostream& operator<<(ostream& os, const modint& self) { return os << raw(self); }
  explicit operator bool() const { return v != 0; }
};/*}}}*/
using mint = modint<998244353>;
int n;
mint _[2][60], *f = _[0] + 30, *g = _[1] + 30;
int mian() {
  cin >> n;
  memset(_, 0, sizeof _);
  g[0] = 1;
  mint ans = 0;
  bool flag = false;
  for (int i = 1; i <= n; i++) {
    swap(f, g);
    int lim = 25;
    for (int j = -lim - 1; j <= lim + 1; j++) g[j] = 0;
    for (int j = -lim; j <= lim; j++) if (f[j]) g[j + 1] += f[j], g[j - 1] += f[j];
    int nlim = max(2, 22 - i);
    int a, b;
    cin >> a >> b;
    if (a != -1) {
      if (a + b != i) flag = true;
      for (int j = -lim - 1; j <= lim + 1; j++) if (abs(j) != abs(a - b)) g[j] = 0;
    }
    if (i == n) {
      for (int j = -lim - 1; j <= lim + 1; j++) if (abs(j) >= nlim) ans += g[j];
    } else {
      for (int j = -lim - 1; j <= lim + 1; j++) if (abs(j) >= nlim) g[j] = 0;
    }
  }
  if (flag) ans = 0;
  cout << ans << endl;
  return 0;
}
int main() {
#ifndef LOCAL
  cin.tie(nullptr)->sync_with_stdio(false);
#endif
  int t;
  cin >> t;
  while (t--) mian();
  return 0;
}

详细

Test #1:

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

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: 0ms
memory: 3688kb

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: 39ms
memory: 3696kb

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: 39ms
memory: 3652kb

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: 41ms
memory: 3716kb

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: 0
Accepted
time: 41ms
memory: 3632kb

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:

ok 20000 lines

Test #7:

score: 0
Accepted
time: 42ms
memory: 3644kb

input:

20000
15
-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
16
-1 -1
0 2
2 1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
2 9
9 3
-1 -1
-1 -1
-1 -1
-1 -1
15
-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
18
-1 -1
-1 -1
-1...

output:

2002
54
2002
0
0
0
6336
0
10
0
0
0
0
0
0
0
0
0
184756
0
0
2
0
0
0
115200
0
0
42
0
60
2
0
0
0
0
64680
572
0
0
0
0
0
0
2002
38896
0
0
0
0
0
132
0
0
378
0
0
0
0
144
0
0
0
70
0
0
160
0
0
0
0
0
0
0
3300
0
0
22
0
0
0
54054
117600
0
132
0
0
0
0
0
870
0
0
0
572
0
0
0
0
0
0
1144
0
0
6006
110880
0
6006
0
0
0
...

result:

ok 20000 lines

Test #8:

score: 0
Accepted
time: 42ms
memory: 3588kb

input:

20000
23
0 1
2 0
-1 -1
4 0
-1 -1
-1 -1
3 4
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
7 12
-1 -1
-1 -1
-1 -1
-1 -1
18
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
3 8
-1 -1
8 5
-1 -1
-1 -1
-1 -1
12 5
-1 -1
12
-1 -1
-1 -1
-1 -1
-1 -1
4 1
-1 -1
-1 -1
2 6
-1 -1
10 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
56
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
12
0
0
0
0
0
0
0
0
0
0
0
21504
0
0
0
0
0
0
0
0
132
0
0
0
0
0
2
2160
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
13608
0
0
15120
0
0
0
0
0
0
0
0
2
0
0
0
0
0
30
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 20000 lines

Test #9:

score: 0
Accepted
time: 67ms
memory: 3632kb

input:

20000
18
-1 -1
-1 -1
2 1
-1 -1
-1 -1
-1 -1
4 3
4 4
4 5
-1 -1
-1 -1
-1 -1
4 9
9 5
9 6
6 10
7 10
-1 -1
24
1 0
-1 -1
1 2
1 3
2 3
-1 -1
-1 -1
-1 -1
5 4
6 4
7 4
-1 -1
7 6
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
10 10
11 10
11 11
12 11
13 11
18
-1 -1
1 1
1 2
-1 -1
3 2
3 3
3 4
-1 -1
-1 -1
-1 -1
-1 -1
5 7
6 7
7...

output:

120
8400
720
72
3840
480
16
168
180
320
896
180
420
48
48
112
3600
160
480
6
32
48
280
240
120
240
192
576
12
48
1440
384
160
18
192
480
32
176
1536
80
22680
360
2688
3888
60
3840
10
1600
5600
1728
216
384
256
210
176
5400
144
3360
108
0
4
72
48
768
6912
24
96
48
10368
30
2880
0
576
360
48
1440
480
...

result:

ok 20000 lines

Test #10:

score: 0
Accepted
time: 55ms
memory: 3620kb

input:

20000
20
-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
15
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
10 3
-1 -1
11 4
18
-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:

184756
572
38896
2002
22176
184756
7722
288
2002
880
672
38896
16016
6006
0
46200
41160
630
45760
0
369512
9900
739024
87516
5760
366080
6006
8008
257400
6006
52920
77220
14280
48620
8820
54054
184756
13552
31680
6006
6006
87516
672
232848
840
87516
8400
184756
27440
87516
38896
38896
31680
205920
3...

result:

ok 20000 lines

Test #11:

score: 0
Accepted
time: 34ms
memory: 3604kb

input:

10000
16
-1 -1
1 1
-1 -1
-1 -1
1 4
1 5
1 6
-1 -1
3 6
-1 -1
4 7
4 8
9 4
-1 -1
-1 -1
11 5
18
1 0
-1 -1
-1 -1
-1 -1
3 2
4 2
-1 -1
2 6
-1 -1
2 8
3 8
-1 -1
-1 -1
-1 -1
-1 -1
6 10
-1 -1
11 7
26
-1 -1
1 1
2 1
-1 -1
-1 -1
4 2
-1 -1
4 4
-1 -1
5 5
-1 -1
6 6
-1 -1
-1 -1
7 8
-1 -1
-1 -1
9 9
-1 -1
10 10
-1 -1
-1...

output:

16
200
18432
96
1152
768
108
25200
192
2400
5280
384
80
96
1200
192
368640
8
4320
240
144
108
180
462
1600
4320
576
12
32
96
5376
792
15552
128
72
2304
80
72
36
6
96
480
48
720
48
208
26880
6912
30
6
1536
192
16
24
60
132
60
3360
128
480
384
3072
6
144
192
2304
840
5940
2304
384
18
360
168
3240
1080...

result:

ok 10000 lines

Test #12:

score: 0
Accepted
time: 30ms
memory: 3644kb

input:

10000
18
-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
18
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
5 2
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
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...

output:

38896
12474
369512
38896
4200
55440
38896
220
2002
16016
184756
739024
369512
514800
16016
6006
739024
87516
1524
3120
291720
105840
5940
184756
87516
6006
184756
16016
16016
1478048
91520
2002
112
184756
4290
87516
2002
2520
10584
63504
8008
87516
38896
184756
128700
68640
19448
16016
8008
240240
1...

result:

ok 10000 lines

Test #13:

score: 0
Accepted
time: 82ms
memory: 3620kb

input:

500
995
0 1
-1 -1
2 1
2 2
-1 -1
3 3
3 4
-1 -1
4 5
-1 -1
-1 -1
-1 -1
-1 -1
5 9
6 9
-1 -1
10 7
8 10
9 10
-1 -1
-1 -1
-1 -1
12 11
-1 -1
-1 -1
13 13
-1 -1
-1 -1
-1 -1
15 15
15 16
16 16
17 16
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
20 19
-1 -1
-1 -1
21 21
22 21
22 22
-1 -1
23 23
24 23
-1 -1
-1 -1
25 25
25 26
26 26...

output:

0
0
885589515
295196505
646720429
0
0
456840382
0
0
194011298
0
477738172
713448436
955476344
0
0
182541667
0
856008466
772934677
0
0
238869086
0
590393010
196101077
885589515
0
0
0
182541667
0
0
884196329
559094632
0
0
885589515
646720429
590393010
0
869940326
0
856332609
0
306666136
0
322315325
15...

result:

ok 500 lines

Test #14:

score: 0
Accepted
time: 62ms
memory: 3568kb

input:

500
998
0 1
-1 -1
-1 -1
-1 -1
3 2
-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
-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...

output:

636540367
0
79228700
313583759
483434828
0
275319451
0
0
483434828
313583759
636540367
0
624753596
774272553
0
483434828
241717414
713448436
0
483434828
111840979
103033451
636540367
0
0
0
0
0
0
966869656
274836381
0
0
0
627167518
0
966869656
515843553
825765125
241717414
0
141104531
0
56865085
8545...

result:

ok 500 lines

Test #15:

score: 0
Accepted
time: 84ms
memory: 3620kb

input:

5
99995
-1 -1
1 1
-1 -1
-1 -1
-1 -1
-1 -1
5 2
3 5
4 5
5 5
-1 -1
5 7
5 8
-1 -1
-1 -1
9 7
8 9
8 10
10 9
10 10
11 10
-1 -1
-1 -1
12 12
-1 -1
-1 -1
13 14
14 14
14 15
-1 -1
-1 -1
16 16
-1 -1
-1 -1
18 17
-1 -1
19 18
19 19
-1 -1
-1 -1
20 21
-1 -1
-1 -1
22 22
23 22
-1 -1
24 23
24 24
-1 -1
25 25
-1 -1
-1 -1
...

output:

0
0
0
801524002
0

result:

ok 5 lines

Test #16:

score: 0
Accepted
time: 71ms
memory: 3644kb

input:

5
99998
-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
-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
19 20
-1 -1
-1 -1
-1 -1
-1 -1
22 22
-1 -1
-1 -1
-1 -1
-1 -1
-1 -...

output:

679063850
0
337747770
461093795
0

result:

ok 5 lines