QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#506585 | #7623. Coloring Tape | ucup-team1198 | WA | 1ms | 5932kb | C++14 | 5.1kb | 2024-08-05 19:53:38 | 2024-08-05 19:53:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int add(int a, int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
const int MAXN = 14, MAXM = 510;
int need[MAXN][MAXM];
int nptr[MAXN][MAXM];
vector<array<int, 2>> restr[MAXM];
vector<int> dp0[3 << MAXN];
vector<int> dp1[3 << 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());
int maxr = 0;
vector<array<int, 2>> st;
for (auto elem : restr[c]) {
if (!st.empty() && st.back()[0] == elem[0]) st.pop_back();
if (elem[1] <= maxr) continue;
maxr = elem[1];
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;
}
}
}
fill(dp0, dp0 + (3 << n), vector<int>(1, 0));
dp0[(1 << n) - 1][0] = 1;
for (int cell = 0; cell < n * m; ++cell) {
int r = cell % n;
int c = cell / n;
/// cerr << r << " " << c << " " << nptr[r][c] << endl;
if (r == 0) {
for (int mask = 0; mask < (3 << n); ++mask) {
int val = dp0[mask].back();
if (mask >= (1 << n)) val = 0;
dp0[mask].resize(restr[c].size() + 1);
fill(dp0[mask].begin(), dp0[mask].end(), 0);
dp0[mask][0] = val;
}
}
if (need[r][c]) {
for (int mask = 0; mask < (1 << n); ++mask) {
fill(dp0[mask].begin(), dp0[mask].end(), 0);
}
}
for (int mask = 0; mask < (3 << n); ++mask) {
for (int ptr = 0; ptr < (int)restr[c].size(); ++ptr) {
if (r >= restr[c][ptr][1]) {
dp0[mask][ptr] = 0;
}
}
}
for (int mask = 0; mask < (3 << n); ++mask) {
dp1[mask].resize(restr[c].size() + 1);
fill(dp1[mask].begin(), dp1[mask].end(), 0);
}
/// cerr << "prep done" << endl;
for (int mask = 0; mask < (3 << n); ++mask) {
int tp = (mask >> n);
int to_left = (mask >> r) & 1;
for (int ptr = 0; ptr <= (int)restr[c].size(); ++ptr) {
if (dp0[mask][ptr] == 0) continue;
/// cerr << mask << "-" << ptr << endl;
auto vert = [&](int nmask) {
dp1[nmask][ptr] = add(dp1[nmask][ptr], dp0[mask][ptr]);
};
auto no_vert = [&](int nmask) {
dp1[nmask][nptr[r][c]] = add(dp1[nmask][nptr[r][c]], dp0[mask][ptr]);
};
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);
/// cerr << "->" << nmask << endl;
no_vert(nmask);
/// cerr << dp1[nmask][0] << endl;
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);
/// cerr << "->" << nmask << endl;
no_vert(nmask);
/// cerr << dp1[nmask][0] << endl;
}
}
}
}
for (int i = 0; i < (3 << n); ++i) {
swap(dp0[i], dp1[i]);
}
}
int ans = dp0[0].back();
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5880kb
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: 5884kb
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: -100
Wrong Answer
time: 1ms
memory: 5932kb
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:
29028
result:
wrong answer 1st numbers differ - expected: '28131', found: '29028'