编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#116928 #1476. [L3-2] 个性题目名称 Accepted 100 1290 ms 13560 K C++ 17 / 5.2 K 滴蜡熊 2025-04-17 22:23:07
显示原始代码
// o4-mini

#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    if (!(cin >> n >> m))
        return 0;
    int N = n * m;
    vector<int> init_mask(N);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> init_mask[i * m + j];
        }
    }
    // Precompute possible domains
    vector<vector<int>> D(N);
    auto is_straight = [&](int x) { return x == 5 || x == 10; };
    for (int id = 0; id < N; id++) {
        int mask = init_mask[id];
        int deg = __builtin_popcount(mask);
        if (deg != 2) {
            D[id] = { mask };
        } else {
            if (is_straight(mask)) {
                D[id] = { 5, 10 };
            } else {
                D[id] = { 3, 6, 12, 9 };
            }
        }
    }
    // Boundary pruning
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int id = i * m + j;
            auto &v = D[id];
            vector<int> tmp;
            for (int mask : v) {
                if (i == 0 && (mask & 1))
                    continue;
                if (j == m - 1 && (mask & 2))
                    continue;
                if (i == n - 1 && (mask & 4))
                    continue;
                if (j == 0 && (mask & 8))
                    continue;
                tmp.push_back(mask);
            }
            v.swap(tmp);
            if (v.empty()) {
                cout << -1;
                return 0;
            }
        }
    }
    // Build adjacency
    vector<vector<pair<int, int>>> adj(N);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int id = i * m + j;
            if (i > 0) {
                adj[id].emplace_back((i - 1) * m + j, 0);
            }
            if (j < m - 1) {
                adj[id].emplace_back(i * m + (j + 1), 1);
            }
            if (i < n - 1) {
                adj[id].emplace_back((i + 1) * m + j, 2);
            }
            if (j > 0) {
                adj[id].emplace_back(i * m + (j - 1), 3);
            }
        }
    }
    // AC-3
    deque<pair<int, int>> que;
    for (int u = 0; u < N; u++) {
        for (auto &pr : adj[u]) {
            que.emplace_back(u, pr.first);
        }
    }
    while (!que.empty()) {
        auto [i, j] = que.front();
        que.pop_front();
        int di = -1;
        // find direction i->j
        for (auto &pr : adj[i])
            if (pr.first == j) {
                di = pr.second;
                break;
            }
        int od = di ^ 2;
        bool revised = false;
        vector<int> keep;
        for (int p : D[i]) {
            bool ok = false;
            int bit_i = (p >> di) & 1;
            for (int q : D[j]) {
                if (((q >> od) & 1) == bit_i) {
                    ok = true;
                    break;
                }
            }
            if (ok)
                keep.push_back(p);
        }
        if (keep.size() < D[i].size()) {
            D[i].swap(keep);
            if (D[i].empty()) {
                cout << -1;
                return 0;
            }
            for (auto &pr : adj[i]) {
                int k = pr.first;
                if (k == j)
                    continue;
                que.emplace_back(k, i);
            }
        }
    }
    // Assignment propagation per component
    vector<int> ans(N, -1);
    vector<char> seen(N, 0);
    vector<char> in_comp(N, 0);
    vector<int> comp;
    vector<int> local_ans(N, -1);
    for (int start = 0; start < N; start++) {
        if (ans[start] != -1)
            continue;
        // gather component
        comp.clear();
        deque<int> dq;
        dq.push_back(start);
        in_comp[start] = 1;
        comp.push_back(start);
        while (!dq.empty()) {
            int u = dq.front();
            dq.pop_front();
            for (auto &pr : adj[u]) {
                int v = pr.first;
                if (!in_comp[v]) {
                    in_comp[v] = 1;
                    comp.push_back(v);
                    dq.push_back(v);
                }
            }
        }
        // reset in_comp flags
        for (int u : comp) in_comp[u] = 0;
        bool solved = false;
        int root = start;
        for (int p0 : D[root]) {
            // reset local_ans for comp
            for (int u : comp) local_ans[u] = -1;
            // assign root
            local_ans[root] = p0;
            deque<int> q0;
            q0.push_back(root);
            bool fail = false;
            while (!q0.empty() && !fail) {
                int u = q0.front();
                q0.pop_front();
                for (auto &pr : adj[u]) {
                    int v = pr.first;
                    int d = pr.second, od2 = d ^ 2;
                    int need = (local_ans[u] >> d) & 1;
                    if (local_ans[v] != -1) {
                        if (((local_ans[v] >> od2) & 1) != need) {
                            fail = true;
                            break;
                        }
                        continue;
                    }
                    // pick matching
                    int pick = -1;
                    for (int qmask : D[v]) {
                        if (((qmask >> od2) & 1) == need) {
                            pick = qmask;
                            break;
                        }
                    }
                    if (pick < 0) {
                        fail = true;
                        break;
                    }
                    local_ans[v] = pick;
                    q0.push_back(v);
                }
            }
            if (!fail) {
                solved = true;
                for (int u : comp) ans[u] = local_ans[u];
                break;
            }
        }
        if (!solved) {
            cout << -1;
            return 0;
        }
    }
    // output
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cout << ans[i * m + j] << (j + 1 < m ? ' ' : '\n');
        }
    }
    return 0;
}
子任务 #1
Accepted
得分:20
测试点 #1
Accepted
得分:100
用时:2 ms
内存:244 KiB

输入文件(t0.in

3 3
4 6 3
1 7 12
0 12 8

答案文件(t0.out

4 6 12
1 7 9
0 3 8

用户输出

4 6 12
1 7 9
0 3 8

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:2 ms
内存:344 KiB

输入文件(t1.in

2 3
3 14 12
3 11 12

答案文件(t1.out

6 14 12
3 11 9

用户输出

6 14 12
3 11 9

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:3 ms
内存:384 KiB

输入文件(t2.in

1 2
1 1

答案文件(t2.out

-1

用户输出

-1

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:2 ms
内存:240 KiB

输入文件(t3.in

2 4
9 8 4 4
12 8 12 3

答案文件(t3.out

6 8 4 4
3 8 3 9

用户输出

6 8 4 4
3 8 3 9

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
子任务 #2
Accepted
得分:80
测试点 #1
Accepted
得分:100
用时:86 ms
内存:13436 KiB

输入文件(t4.in

308 324
4 0 0 0 4 9 12 0 0 0 9 10 8 2 14 14 12 0 4 0 9 3 2 9 4 9 5 3 2 14 14 6 2 8 9 8 4 0 4 0 6 12 
<236699 bytes omitted>

答案文件(t4.out

4 0 0 0 4 6 12 0 0 0 6 10 8 2 14 14 12 0 4 0 6 12 2 12 4 6 10 12 2 14 14 12 2 8 6 8 4 0 4 0 6 12 0 4
<236631 bytes omitted>

用户输出

4 0 0 0 4 6 12 0 0 0 6 10 8 2 14 14 12 0 4 0 6 12 2 12 4 6 10 12 2 14 14 12 2 8 6 8 4 0 4 0 6 12 0 4 4 0 0 6 14 8 4 4 2 12 4 4 2
<236603 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:82 ms
内存:13424 KiB

输入文件(t5.in

308 324
4 0 2 5 6 0 2 8 6 8 4 0 4 3 14 10 14 14 14 5 14 14 9 4 2 3 2 14 8 0 2 8 2 9 2 5 14 14 14 8 4
<236485 bytes omitted>

答案文件(t5.out

4 0 2 10 12 0 2 8 6 8 4 0 4 6 14 10 14 14 14 10 14 14 12 4 2 12 2 14 8 0 2 8 2 12 2 10 14 14 14 8 4 
<236524 bytes omitted>

用户输出

4 0 2 10 12 0 2 8 6 8 4 0 4 6 14 10 14 14 14 10 14 14 12 4 2 12 2 14 8 0 2 8 2 12 2 10 14 14 14 8 4 2 14 12 2 8 4 6 10 8 2 12 0 
<236496 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:74 ms
内存:13436 KiB

输入文件(t6.in

308 324
0 2 8 6 3 12 14 14 8 0 2 3 2 14 8 4 4 2 8 0 12 12 3 3 2 8 2 6 0 12 3 12 5 14 10 8 0 12 10 5 
<236881 bytes omitted>

答案文件(t6.out

0 2 8 6 12 6 14 14 8 0 2 12 2 14 8 4 4 2 8 0 6 12 6 12 2 8 2 12 0 6 12 6 10 14 10 8 0 6 10 10 10 12 
<236913 bytes omitted>

用户输出

0 2 8 6 12 6 14 14 8 0 2 12 2 14 8 4 4 2 8 0 6 12 6 12 2 8 2 12 0 6 12 6 10 14 10 8 0 6 10 10 10 12 4 4 4 4 6 14 12 4 4 6 10 12 
<236885 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:86 ms
内存:13436 KiB

输入文件(t7.in

308 324
0 0 4 2 5 10 9 4 2 3 4 0 0 0 4 2 8 0 9 3 4 4 0 0 4 0 0 0 6 9 6 9 12 6 2 6 4 2 12 4 0 2 14 9 
<236699 bytes omitted>

答案文件(t7.out

0 0 4 2 10 10 12 4 2 12 4 0 0 0 4 2 8 0 6 12 4 4 0 0 4 0 0 0 6 12 6 12 6 12 2 12 4 2 12 4 0 2 14 12 
<236743 bytes omitted>

用户输出

0 0 4 2 10 10 12 4 2 12 4 0 0 0 4 2 8 0 6 12 4 4 0 0 4 0 0 0 6 12 6 12 6 12 2 12 4 2 12 4 0 2 14 12 0 4 2 14 12 6 12 0 0 6 10 14
<236715 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:90 ms
内存:13460 KiB

输入文件(t8.in

308 324
12 5 10 14 14 14 14 9 12 10 8 6 8 0 2 5 8 2 8 9 8 4 2 14 3 4 2 9 2 10 10 10 14 12 4 0 9 14 3
<236523 bytes omitted>

答案文件(t8.out

6 10 10 14 14 14 14 12 6 10 8 6 8 0 2 10 8 2 8 6 8 4 2 14 12 4 2 12 2 10 10 10 14 12 4 0 6 14 12 6 1
<236523 bytes omitted>

用户输出

6 10 10 14 14 14 14 12 6 10 8 6 8 0 2 10 8 2 8 6 8 4 2 14 12 4 2 12 2 10 10 10 14 12 4 0 6 14 12 6 10 14 14 14 14 14 14 10 10 10
<236495 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #6
Accepted
得分:100
用时:85 ms
内存:13488 KiB

输入文件(t9.in

308 324
0 2 14 14 3 2 14 9 6 10 14 10 9 4 0 3 14 8 4 0 6 8 0 2 14 14 14 5 8 0 2 10 8 4 9 5 3 4 0 12 
<236956 bytes omitted>

答案文件(t9.out

0 2 14 14 12 2 14 12 6 10 14 10 12 4 0 6 14 8 4 0 6 8 0 2 14 14 14 10 8 0 2 10 8 4 6 10 12 4 0 6 12 
<236670 bytes omitted>

用户输出

0 2 14 14 12 2 14 12 6 10 14 10 12 4 0 6 14 8 4 0 6 8 0 2 14 14 14 10 8 0 2 10 8 4 6 10 12 4 0 6 12 6 8 0 6 14 12 0 4 0 4 2 8 6 
<236642 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #7
Accepted
得分:100
用时:100 ms
内存:13436 KiB

输入文件(t10.in

308 324
4 0 4 9 14 9 6 8 2 3 0 12 10 14 8 3 8 2 8 0 0 0 2 9 2 14 10 14 8 2 14 12 4 0 2 8 0 0 0 3 9 0
<236930 bytes omitted>

答案文件(t10.out

4 0 4 6 14 12 6 8 2 12 0 6 10 14 8 6 8 2 8 0 0 0 2 12 2 14 10 14 8 2 14 12 4 0 2 8 0 0 0 6 12 0 2 10
<236670 bytes omitted>

用户输出

4 0 4 6 14 12 6 8 2 12 0 6 10 14 8 6 8 2 8 0 0 0 2 12 2 14 10 14 8 2 14 12 4 0 2 8 0 0 0 6 12 0 2 10 10 14 12 0 6 12 0 0 6 12 2 
<236642 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #8
Accepted
得分:100
用时:89 ms
内存:13420 KiB

输入文件(t11.in

308 324
4 2 9 0 4 4 2 14 8 12 12 9 10 3 2 14 14 8 0 3 8 0 2 8 9 14 12 9 8 2 12 3 5 14 14 8 2 5 14 8 
<236642 bytes omitted>

答案文件(t11.out

4 2 12 0 4 4 2 14 8 6 12 6 10 12 2 14 14 8 0 6 8 0 2 8 6 14 12 6 8 2 12 6 10 14 14 8 2 10 14 8 6 12 
<236752 bytes omitted>

用户输出

4 2 12 0 4 4 2 14 8 6 12 6 10 12 2 14 14 8 0 6 8 0 2 8 6 14 12 6 8 2 12 6 10 14 14 8 2 10 14 8 6 12 6 14 12 4 6 10 8 0 2 14 8 2 
<236724 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #9
Accepted
得分:100
用时:61 ms
内存:13560 KiB

输入文件(t12.in

308 324
4 6 8 4 2 10 8 4 3 10 10 3 4 2 6 2 14 9 2 14 9 4 4 12 12 12 14 14 8 4 4 2 14 6 2 14 14 8 0 2
<236705 bytes omitted>

答案文件(t12.out

4 6 8 4 2 10 8 4 6 10 10 12 4 2 12 2 14 12 2 14 12 4 4 6 12 6 14 14 8 4 4 2 14 12 2 14 14 8 0 2 12 4
<236587 bytes omitted>

用户输出

4 6 8 4 2 10 8 4 6 10 10 12 4 2 12 2 14 12 2 14 12 4 4 6 12 6 14 14 8 4 4 2 14 12 2 14 14 8 0 2 12 4 0 6 14 14 8 0 0 2 10 10 12 
<236559 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #10
Accepted
得分:100
用时:91 ms
内存:13436 KiB

输入文件(t13.in

308 324
0 4 0 12 8 2 3 0 0 0 2 5 6 4 4 0 4 2 8 3 3 0 2 14 10 10 8 4 9 5 5 8 4 2 8 3 14 8 2 8 0 4 2 8
<236584 bytes omitted>

答案文件(t13.out

0 4 0 6 8 2 12 0 0 0 2 10 12 4 4 0 4 2 8 6 12 0 2 14 10 10 8 4 6 10 10 8 4 2 8 6 14 8 2 8 0 4 2 8 2 
<236847 bytes omitted>

用户输出

0 4 0 6 8 2 12 0 0 0 2 10 12 4 4 0 4 2 8 6 12 0 2 14 10 10 8 4 6 10 10 8 4 2 8 6 14 8 2 8 0 4 2 8 2 14 10 8 4 2 12 0 4 4 2 14 8 
<236819 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #11
Accepted
得分:100
用时:92 ms
内存:13436 KiB

输入文件(t14.in

308 324
4 0 9 14 8 3 14 8 2 14 14 14 8 2 5 10 8 4 2 12 2 8 2 14 14 14 10 5 14 8 4 2 8 0 6 8 2 10 9 0
<236723 bytes omitted>

答案文件(t14.out

4 0 6 14 8 6 14 8 2 14 14 14 8 2 10 10 8 4 2 12 2 8 2 14 14 14 10 10 14 8 4 2 8 0 6 8 2 10 12 0 6 12
<236762 bytes omitted>

用户输出

4 0 6 14 8 6 14 8 2 14 14 14 8 2 10 10 8 4 2 12 2 8 2 14 14 14 10 10 14 8 4 2 8 0 6 8 2 10 12 0 6 12 0 4 6 14 12 2 8 4 4 0 2 12 
<236734 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #12
Accepted
得分:100
用时:80 ms
内存:13436 KiB

输入文件(t15.in

308 324
4 0 2 8 2 8 0 4 0 0 9 14 5 3 4 2 8 2 3 0 3 14 14 8 4 0 4 2 3 9 14 5 14 6 4 4 9 14 8 12 12 4 
<236529 bytes omitted>

答案文件(t15.out

4 0 2 8 2 8 0 4 0 0 6 14 10 12 4 2 8 2 12 0 6 14 14 8 4 0 4 2 12 6 14 10 14 12 4 4 6 14 8 6 12 4 2 8
<236621 bytes omitted>

用户输出

4 0 2 8 2 8 0 4 0 0 6 14 10 12 4 2 8 2 12 0 6 14 14 8 4 0 4 2 12 6 14 10 14 12 4 4 6 14 8 6 12 4 2 8 4 2 14 14 10 8 6 8 4 2 14 1
<236593 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #13
Accepted
得分:100
用时:117 ms
内存:13424 KiB

输入文件(t16.in

308 324
12 14 8 2 12 0 2 5 14 14 8 0 2 8 0 2 8 2 9 4 4 12 8 0 2 12 3 14 14 14 8 0 0 2 14 9 2 10 8 2 
<236836 bytes omitted>

答案文件(t16.out

6 14 8 2 12 0 2 10 14 14 8 0 2 8 0 2 8 2 12 4 4 6 8 0 2 12 6 14 14 14 8 0 0 2 14 12 2 10 8 2 12 4 6 
<236672 bytes omitted>

用户输出

6 14 8 2 12 0 2 10 14 14 8 0 2 8 0 2 8 2 12 4 4 6 8 0 2 12 6 14 14 14 8 0 0 2 14 12 2 10 8 2 12 4 6 12 6 12 6 10 8 6 8 0 0 6 8 6
<236644 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #14
Accepted
得分:100
用时:70 ms
内存:13412 KiB

输入文件(t17.in

308 324
2 14 3 0 0 0 0 0 2 3 0 2 14 12 9 14 8 2 8 0 2 14 14 5 3 2 14 3 2 8 4 2 8 9 12 3 14 14 8 12 9
<236890 bytes omitted>

答案文件(t17.out

2 14 12 0 0 0 0 0 2 12 0 2 14 12 6 14 8 2 8 0 2 14 14 10 12 2 14 12 2 8 4 2 8 6 12 6 14 14 8 6 12 6 
<236868 bytes omitted>

用户输出

2 14 12 0 0 0 0 0 2 12 0 2 14 12 6 14 8 2 8 0 2 14 14 10 12 2 14 12 2 8 4 2 8 6 12 6 14 14 8 6 12 6 12 2 12 0 4 6 14 12 2 10 8 6
<236840 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #15
Accepted
得分:100
用时:76 ms
内存:13400 KiB

输入文件(t18.in

308 324
3 10 5 14 6 2 5 14 10 10 12 9 10 10 8 4 0 2 10 12 2 12 12 8 0 2 10 8 12 5 14 8 0 0 4 0 4 0 9
<236699 bytes omitted>

答案文件(t18.out

6 10 10 14 12 2 10 14 10 10 12 6 10 10 8 4 0 2 10 12 2 12 6 8 0 2 10 8 6 10 14 8 0 0 4 0 4 0 6 8 6 8
<236759 bytes omitted>

用户输出

6 10 10 14 12 2 10 14 10 10 12 6 10 10 8 4 0 2 10 12 2 12 6 8 0 2 10 8 6 10 14 8 0 0 4 0 4 0 6 8 6 8 6 8 6 10 14 12 0 2 10 12 4 
<236731 bytes omitted>

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0
测试点 #16
Accepted
得分:100
用时:2 ms
内存:276 KiB

输入文件(t19.in

4 4
6 10 8 0
7 8 0 0
5 12 5 8
6 11 8 0

答案文件(t19.out

6 10 8 0
7 8 0 0
5 6 10 8
3 11 8 0

用户输出

6 10 8 0
7 8 0 0
5 6 10 8
3 11 8 0

Special Judge 信息

Accepted | correct

系统信息

Exited with return code 0