QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#506732 | #7623. Coloring Tape | ucup-team1198 | TL | 1165ms | 9148kb | C++14 | 4.7kb | 2024-08-05 20:59:44 | 2024-08-05 20:59:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int MAXN = 14, MAXM = 510;
int need[MAXN][MAXM];
int nptr[MAXN][MAXM];
vector<array<int, 2>> restr[MAXM];
int64_t dp0[3 << MAXN][MAXN];
int64_t dp1[3 << MAXN][MAXN];
void solve_() {
int n, m, r;
cin >> n >> m >> r;
bool bad = false;
while (r--) {
int c, l, r, diff;
cin >> c >> l >> r >> diff;
--c;
if (c == 0) {
if (diff == 0) bad = true;
continue;
}
if (diff == 0) {
for (int i = l; i < r; ++i) {
need[i][c] = true;
}
} else {
--l; --r;
restr[c].push_back({l, r});
}
}
if (bad) {
cout << "0\n";
return;
}
for (int c = 0; c < m; ++c) {
sort(restr[c].begin(), restr[c].end());
vector<array<int, 2>> st;
for (auto elem : restr[c]) {
while (!st.empty() && st.back()[1] >= elem[1]) st.pop_back();
if (!st.empty() && st.back()[0] == elem[0]) continue;
st.push_back(elem);
}
restr[c] = st;
for (int i = 0; i < n; ++i) {
nptr[i][c] = st.size();
}
for (int i = (int)st.size() - 1; i >= 0; --i) {
for (int r = st[i][0] - 1; r >= 0; --r) {
nptr[r][c] = i;
}
}
}
dp0[(1 << n) - 1][0] = 1;
int lsz = 0;
for (int cell = 0; cell < n * m; ++cell) {
int r = cell % n;
int c = cell / n;
int csz = restr[c].size();
if (r == 0) {
for (int mask = 0; mask < (3 << n); ++mask) {
int val = dp0[mask][lsz];
if (mask >= (1 << n)) val = 0;
fill(dp0[mask], dp0[mask] + csz + 1, 0);
dp0[mask][0] = val;
}
}
if (need[r][c]) {
for (int mask = 0; mask < (1 << n); ++mask) {
fill(dp0[mask], dp0[mask] + csz + 1, 0);
}
}
for (int mask = 0; mask < (3 << n); ++mask) {
for (int ptr = 0; ptr < csz; ++ptr) {
if (r >= restr[c][ptr][1]) {
dp0[mask][ptr] = 0;
}
}
}
for (int mask = 0; mask < (3 << n); ++mask) {
fill(dp1[mask], dp1[mask] + csz + 1, 0);
}
for (int mask = 0; mask < (3 << n); ++mask) {
int tp = (mask >> n);
int to_left = (mask >> r) & 1;
for (int ptr = 0; ptr <= csz; ++ptr) {
if (dp0[mask][ptr] == 0) continue;
auto vert = [&](int nmask) {
dp1[nmask][ptr] += dp0[mask][ptr];
if (dp1[nmask][ptr] >= MOD) dp1[nmask][ptr] -= MOD;
};
auto no_vert = [&](int nmask) {
dp1[nmask][nptr[r][c]] += dp0[mask][ptr];
if (dp1[nmask][nptr[r][c]] >= MOD) dp1[nmask][nptr[r][c]] -= MOD;
};
if (to_left == 0) {
if (tp == 0) {
int nmask = mask | (1 << n);
vert(nmask);
nmask |= (1 << r);
vert(nmask);
} else if (tp == 1) {
int nmask = mask;
vert(nmask);
} else {
int nmask = mask;
vert(nmask);
nmask ^= (2 << n);
no_vert(nmask);
nmask ^= (1 << r);
no_vert(nmask);
}
} else {
if (tp == 0) {
int nmask = mask;
no_vert(nmask);
nmask ^= (1 << r);
no_vert(nmask);
nmask ^= (2 << n);
vert(nmask);
} else if (tp == 1) {
int nmask = mask ^ (1 << r) ^ (1 << n);
no_vert(nmask);
}
}
}
}
for (int i = 0; i < (3 << n); ++i) {
for (int j = 0; j <= csz; ++j) {
swap(dp0[i][j], dp1[i][j]);
}
}
lsz = restr[c].size();
}
int ans = dp0[0][lsz];
cout << ans << "\n";
}
/// #define MULTITEST
main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tst = 1;
#ifdef MULTITEST
cin >> tst;
#endif // MULTITEST
while (tst--) {
solve_();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5556kb
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: 5704kb
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: 5684kb
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: 37ms
memory: 5988kb
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: 73ms
memory: 5996kb
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: 106ms
memory: 5960kb
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: 174ms
memory: 6068kb
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: 1095ms
memory: 9148kb
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: 1165ms
memory: 8568kb
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...