QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506723#7623. Coloring Tapeucup-team1198WA 36ms6028kbC++144.8kb2024-08-05 20:56:012024-08-05 20:56:02

Judging History

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

  • [2024-08-05 20:56:02]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:6028kb
  • [2024-08-05 20:56:01]
  • 提交

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);
        }

        if (cell % 20 == 0) {
            for (int mask = 0; mask < (3 << n); ++mask) {
                for (int ptr = 0; ptr <= csz; ++ptr) {
                    dp0[mask][ptr] %= MOD;
                }
            }
        }

        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];
                };

                auto no_vert = [&](int nmask) {
                    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);
                        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] % MOD;
    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: 5604kb

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

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

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: 36ms
memory: 6028kb

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:

-343917879

result:

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