QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#248106#7623. Coloring Tapeucup-team1198#WA 1ms3748kbC++204.7kb2023-11-11 17:31:542023-11-11 17:31:55

Judging History

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

  • [2023-11-11 17:31:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3748kb
  • [2023-11-11 17:31:54]
  • 提交

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

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

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

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'