QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#248075#7623. Coloring Tapeucup-team1198#WA 1ms3696kbC++204.3kb2023-11-11 17:22:282023-11-11 17:22:29

Judging History

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

  • [2023-11-11 17:22:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3696kb
  • [2023-11-11 17:22:28]
  • 提交

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;
        int mx = -1;
        for (auto elem : cond[i]) {
            if (elem[1] > mx) {
                seg.push_back(elem);
                mx = elem[1];
            }
        }
        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;
}

詳細信息

Test #1:

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

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

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

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'