QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#220673#7623. Coloring TapeHeltion#TL 1238ms21828kbC++202.1kb2023-10-20 17:28:422023-10-20 17:28:42

Judging History

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

  • [2023-10-20 17:28:42]
  • 评测
  • 测评结果:TL
  • 用时:1238ms
  • 内存:21828kb
  • [2023-10-20 17:28:42]
  • 提交

answer

#include <bits/extc++.h>
using namespace std;
using i64 = int64_t;
using f64 = double_t;
constexpr int mod = 998244353;
void add(int &x, int y) {
  if ((x += y) >= mod) { x -= mod; }
}
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, m, r;
  cin >> n >> m >> r;
  vector<vector<tuple<int, int, int>>> restr(m + 1);
  for (int i = 0; i < r; i += 1) {
    int c, x, y, diff;
    cin >> c >> x >> y >> diff;
    if (c == 1 and diff == 0) {
      cout << 0;
      return 0;
    }
    restr[c].emplace_back(x, y, diff);
  }
  vector<vector<pair<int, int>>> g(1 << n);
  int edge = 0;
  for (int i = 0; i < (1 << (n - 1)); i += 1) {
    vector<unsigned> p;
    int x = i | (1 << (n - 1)), y = 0;
    for (int j = 0; j < n; j += 1) {
      if ((x >> j) % 2) {
        p.push_back(1 << y | 1 << j);
        y = j + 1;
      }
    }
    for (int j = 0; j < (1 << n); j += 1) {
      function<void(int, int)> dfs = [&](int k, int cur) {
        if (k == size(p)) {
          g[j].emplace_back(i, cur);
          edge += 1;
          return;
        }
        if (j & p[k]) {
          if (popcount(p[k]) == 1) {
            dfs(k + 1, cur | p[k]);
          } else {
            int x = p[k] & -p[k], y = p[k] ^ x;
            if (j & x) { dfs(k + 1, cur | y); }
            if (j & y) { dfs(k + 1, cur | x); }
          }
        }
      };
      dfs(0, 0);
    }
  }
  vector<int> f(1 << n);
  f.back() = 1;
  for (int i = 2; i <= m; i += 1) {
    vector<int> h(1 << n);
    for (int j = 0; j < (1 << n); j += 1) {
      if (f[j]) {
        for (auto [w, t] : g[j]) {
          bool ok = true;
          for (auto [x, y, diff] : restr[i]) {
            x -= 1;
            y -= 1;
            int mask = (1 << y) - (1 << x);
            if (bool(mask & w) != diff) {
              ok = false;
              break;
            }
          }
          if (ok) { add(h[t], f[j]); }
        }
      }
    }
    f.swap(h);
  }
  int ans = 0;
  for (auto fi : f) { add(ans, fi); }
  cout << ans << "\n";
  cerr << edge;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 5 3
3 2 3 0
4 1 2 0
5 1 3 0

output:

19

result:

ok 1 number(s): "19"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

5 10 10
9 3 4 1
2 4 5 0
7 2 3 0
9 2 3 0
6 3 5 0
6 2 4 1
2 4 5 0
1 1 3 1
7 2 4 0
10 2 3 0

output:

1514

result:

ok 1 number(s): "1514"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

5 10 20
8 4 5 0
2 2 5 1
8 4 5 0
10 3 5 0
7 1 3 1
1 2 4 1
6 3 5 1
10 3 5 0
4 1 5 1
7 3 4 1
2 2 4 1
8 3 4 0
9 3 5 0
5 2 5 1
9 4 5 0
9 1 2 0
6 1 5 1
8 3 5 0
2 2 4 1
8 3 5 0

output:

28131

result:

ok 1 number(s): "28131"

Test #4:

score: 0
Accepted
time: 41ms
memory: 4744kb

input:

10 100 200
95 5 7 0
7 4 6 1
62 9 10 0
32 5 8 1
31 2 6 1
75 7 9 1
1 4 7 1
18 7 10 1
75 1 8 1
87 6 9 1
44 7 8 1
68 6 9 1
95 4 6 0
34 1 2 1
70 1 6 1
31 5 9 1
15 6 10 1
48 5 8 1
51 3 7 1
39 5 9 1
23 2 3 1
7 8 9 1
84 7 10 1
13 4 9 1
18 3 6 1
59 9 10 0
31 8 10 1
6 7 9 1
76 3 10 1
41 5 6 0
33 3 4 1
96 1 10...

output:

655333622

result:

ok 1 number(s): "655333622"

Test #5:

score: 0
Accepted
time: 47ms
memory: 4864kb

input:

10 200 200
106 9 10 0
93 4 10 1
199 3 7 0
73 2 9 1
105 8 9 0
38 9 10 1
73 8 10 1
153 3 9 1
123 2 5 1
159 7 9 0
154 5 7 1
162 3 7 0
113 1 5 1
131 7 9 1
67 4 6 1
178 6 10 0
157 7 9 0
147 9 10 0
154 7 10 0
123 3 4 1
39 8 10 1
139 2 9 1
191 9 10 0
36 4 5 1
17 2 8 1
124 3 7 1
9 9 10 1
71 9 10 1
181 7 8 0...

output:

552037151

result:

ok 1 number(s): "552037151"

Test #6:

score: 0
Accepted
time: 49ms
memory: 4652kb

input:

10 300 200
252 1 5 0
48 9 10 1
18 9 10 1
233 9 10 0
195 2 9 1
125 2 5 1
263 7 9 1
24 1 6 1
258 2 10 1
272 8 10 1
76 5 7 1
147 1 7 1
93 9 10 1
30 6 9 1
10 1 10 1
56 2 10 1
93 8 9 1
206 6 9 1
65 1 9 1
226 3 5 0
88 7 8 1
151 3 4 1
292 9 10 0
129 2 3 1
292 9 10 0
180 7 10 1
4 5 10 1
10 9 10 1
151 4 7 1
...

output:

4494096

result:

ok 1 number(s): "4494096"

Test #7:

score: 0
Accepted
time: 68ms
memory: 4904kb

input:

10 500 300
210 4 7 1
341 8 9 0
371 2 5 0
21 4 10 1
370 8 9 0
368 1 6 0
395 7 9 0
287 6 10 1
299 3 7 1
379 1 9 1
164 4 10 1
390 7 9 0
455 6 9 0
208 8 10 1
402 3 10 0
112 8 10 1
279 3 10 1
180 7 10 1
456 2 6 0
121 5 6 1
312 5 7 0
335 8 10 0
318 2 10 1
497 8 10 0
108 8 9 0
247 3 6 1
155 5 6 1
308 1 2 0...

output:

705403853

result:

ok 1 number(s): "705403853"

Test #8:

score: 0
Accepted
time: 844ms
memory: 21828kb

input:

12 500 300
115 3 10 1
152 10 12 1
89 8 12 1
276 4 7 0
467 6 7 0
405 5 9 0
189 4 9 1
197 1 3 1
341 7 8 0
67 7 8 1
266 2 6 1
78 8 12 1
317 11 12 0
417 8 10 0
380 2 8 0
255 2 5 1
80 7 9 1
317 5 11 1
470 5 9 0
373 3 4 0
413 4 10 0
393 9 12 0
362 8 10 1
42 7 12 1
486 3 5 0
229 1 5 0
224 6 7 0
55 3 10 1
4...

output:

378086467

result:

ok 1 number(s): "378086467"

Test #9:

score: 0
Accepted
time: 1238ms
memory: 21632kb

input:

12 500 500
54 11 12 1
325 10 11 0
83 2 3 1
148 3 10 1
165 3 11 1
16 11 12 1
363 8 10 1
78 11 12 1
258 4 12 1
237 8 11 1
403 2 10 1
354 1 9 1
234 4 7 1
454 9 11 0
160 11 12 1
393 1 3 0
375 9 11 0
494 1 3 0
200 6 12 1
414 11 12 0
217 9 10 0
92 5 9 1
172 5 6 1
110 8 12 1
339 4 12 1
429 2 4 0
29 10 11 1...

output:

948753642

result:

ok 1 number(s): "948753642"

Test #10:

score: -100
Time Limit Exceeded

input:

14 500 500
362 4 12 1
225 5 9 1
428 5 9 1
101 8 10 1
488 5 9 0
249 11 14 1
232 2 6 1
220 4 10 1
20 7 13 1
154 4 13 1
480 8 14 0
9 2 4 1
201 7 10 1
174 10 11 0
169 13 14 0
256 10 12 1
403 11 13 0
492 10 14 0
167 6 12 1
123 11 13 1
471 9 10 0
77 5 9 1
51 6 10 1
411 11 14 1
422 11 13 0
7 1 7 1
284 5 11...

output:


result: