QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506599#7623. Coloring Tapeucup-team1198WA 28ms6136kbC++145.1kb2024-08-05 20:01:312024-08-05 20:01:32

Judging History

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

  • [2024-08-05 20:01:32]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:6136kb
  • [2024-08-05 20:01:31]
  • 提交

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());
        vector<array<int, 2>> st;
        for (auto elem : restr[c]) {
            if (!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;
            }
        }
    }
    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;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5944kb

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: 6124kb

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: 5888kb

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: -100
Wrong Answer
time: 28ms
memory: 6136kb

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:

5230051

result:

wrong answer 1st numbers differ - expected: '655333622', found: '5230051'