QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#248114 | #7623. Coloring Tape | ucup-team1198# | TL | 1494ms | 4292kb | C++20 | 4.7kb | 2023-11-11 17:33:34 | 2023-11-11 17:33:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()
const int MOD = 998244353;
int add(int a, int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
const int MAXNM = 15 * 510 + 100;
vector<array<int, 2>> cond[MAXNM];
int can[MAXNM];
const int MAXN = 14;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
fill(can, can + MAXNM, 1);
int n, m, cnd;
cin >> n >> m >> cnd;
for (int i = 0; i < cnd; ++i) {
int c, x, y, d;
cin >> c >> x >> y >> d;
--c;
if (d == 0) {
if (c == 0) {
cout << "0\n";
return 0;
}
for (int i = x; i < y; ++i) {
can[c * n + i] = 0;
}
} else {
if (c == 0) {
continue;
}
cond[c].push_back({x, y});
}
}
for (int i = 1; i < m; ++i) {
sort(cond[i].begin(), cond[i].end(), [](array<int, 2> a, array<int, 2> b) {
if (a[0] == b[0]) return a[1] > b[1];
return a[0] < b[0];
});
vector<array<int, 2>> seg;
for (int t = 0; t < (int)cond[i].size(); ++t) {
bool f = true;
for (int q = 0; q < (int)cond[i].size(); ++q) {
if (t == q) continue;
if (cond[i][q] == cond[i][t] && q < t) {
f = false;
}
if (cond[i][q] == cond[i][t]) continue;
if (cond[i][q][0] >= cond[i][t][0] && cond[i][q][1] <= cond[i][t][1]) {
f = false;
}
}
if (f) {
seg.push_back(cond[i][t]);
}
}
cond[i] = seg;
}
vector<vector<int>> dp((1 << (n + 1)), vector<int>(1, 0));
dp[(1 << n) - 1][0] = 1;
int c = 0, r = n - 1;
int condl = 0, condr = 0;
for (int i = n - 1; i < n * m - 1; ++i) {
if (i == 43) {
/// cerr << " DP: " << dp[28][0] << endl;
}
/// cerr << "i: " << i << endl;
++r;
if (r == n) {
r = 0;
++c;
condl = condr = 0;
}
while (condl < (int)cond[c].size() && cond[c][condl][1] <= r) ++condl;
while (condr < (int)cond[c].size() && cond[c][condr][0] <= r) ++condr;
/// cerr << r << " : " << c << endl;
/// cerr << "borders: " << condl << " " << condr << endl;
vector<vector<int>> dp1((1 << (n + 1)), vector<int>(cond[c].size() + 1, 0));
if (r == 0) {
for (int mask = 0; mask < (1 << n); ++mask) {
if (mask & 1) {
dp1[mask][0] = add(dp1[mask][0], dp[mask].back());
}
dp1[mask | 1 | (1 << n)][0] = add(dp1[mask | 1 | (1 << n)][0], dp[mask].back());
}
/// cerr << dp1[(1 << n) - 1][0] << endl;
dp = move(dp1);
continue;
}
for (int mask = 0; mask < 2 * (1 << n); ++mask) {
int m0 = mask, m1 = mask;
if (mask & (1 << r)) {
m0 ^= (1 << r);
} else {
m1 ^= (1 << r);
}
for (int i = 0; i <= cond[c].size(); ++i) {
if (i < condl || dp[mask][i] == 0) continue;
/// cerr << mask << " " << i << endl;
if (mask >= (1 << n)) {
dp1[m0][i] = add(dp1[m0][i], dp[mask][i]);
if (mask & (1 << r)) {
dp1[m0 - (1 << n)][i] = add(dp1[m0 - (1 << n)][i], dp[mask][i]);
/// cerr << m0 - (1 << n) << " " << i << " " << dp1[m0 - (1 << n)][i] << endl;
}
}
if (mask < (1 << n) && (mask & (1 << (r - 1)))) {
dp1[m1 ^ (1 << (r - 1))][i] = add(dp1[m1 ^ (1 << (r - 1))][i], dp[mask][i]);
/// cerr << (m1 ^ (1 << (r - 1))) << " " << i << " " << dp1[m1 ^ (1 << (r - 1))][i] << endl;
}
if (!can[c * n + r]) continue;
int j = max(i, condr);
if ((mask & (1 << r)) && mask < (1 << n)) {
dp1[m1][j] = add(dp1[m1][j], dp[mask][i]);
/// cerr << m1 << " " << j << " " << dp1[m1][j] << endl;
}
if (mask < (1 << n)) {
dp1[m1 + (1 << n)][j] = add(dp1[m1 + (1 << n)][j], dp[mask][i]);
}
}
}
dp = move(dp1);
}
int ans = 0;
for (int mask = 0; mask < (1 << n); ++mask) {
ans = add(ans, dp[mask].back());
}
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3628kb
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: 1ms
memory: 3648kb
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: 1ms
memory: 3624kb
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: 62ms
memory: 3872kb
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: 126ms
memory: 3940kb
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: 183ms
memory: 3840kb
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: 296ms
memory: 3848kb
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: 1494ms
memory: 4292kb
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: -100
Time Limit Exceeded
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