题目 › fcs-211

FrontierCS #211

FrontierCS 算法赛道 v1.1 · 2026-05 · L5 开放式 · C++17 · 时限 10 秒 · 0–100 连续分

查看原题跳到结果

题面

来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。

Communication Robots ## Problem Description In a task area, there are several robots distributed that must maintain a connected network through wireless communication to complete tasks collaboratively. Wireless communication has the following characteristics: (1) Establishing communication links consumes energy. (2) There are high-power robots with more advanced communication modules, and links connected to them have lower energy consumption. (3) There are also several optional relay stations distributed in the task area that can serve as intermediate nodes for signals, helping to reduce overall energy consumption. Your task is to: Design communication links, reasonably choose whether to enable relay stations, ensure all robots are connected, and minimize the overall energy consumption cost. ## Communication Energy Consumption Rules The square of the Euclidean distance between two nodes is the base value (D) of the communication energy consumption between the two nodes. - The energy consumption cost between an ordinary robot (R) and an ordinary robot (R) is 1 × D. - The energy consumption cost between an ordinary robot (R) and a high-power robot (S) is 0.8 × D. - The energy consumption cost between a high-power robot (S) and a high-power robot (S) is 0.8 × D. - The energy consumption cost between a relay station (C) and any robot (R or S) is 1 × D. - Relay stations (C) cannot communicate directly with each other. ## Goal All robots (R and S) must form a connected network. Any two robots must have a communication path between them, which can be a direct connection or pass through other robots or relay stations. You can choose to use or not use any relay stations. Minimize the overall energy consumption cost. ## Input Format The first line contains two integers: N (number of robots) and K (number of optional relay stations). The next N + K lines each contain: device ID, x-coordinate, y-coordinate, and type. Constraints: - N ≤ 1500, K ≤ 1500 - Type R represents an ordinary robot, S represents a high-power robot, C represents an optional relay station - x-coordinates and y-coordinates are integers in the range [-10000, 10000] ## Output Format The first line: IDs of selected relay stations (if multiple, separated by "#"; if none, output "#"). The second line: Set of communication links (each link is represented as "device_id-device_id", multiple links are separated by "#"). ## Example ### Input ``` 3 1 1 0 0 R 2 100 0 R 3 50 40 S 4 50 0 C ``` ### Output ``` 4 1-3#2-3#3-4 ``` Scoring The physical objective is relay network actual total cost C; smaller is better. The physical reference is `a = 8*D/9`; matching a positive reference earns 60 points. D is the minimum-spanning-tree cost without relay nodes. Define the historical low-score expression (in points): P_low = 60*max(0,(D-C)/(D/9)) for D>0; 0 for D=0 and C>0. A valid solution with `C=0` receives 100 points, including a zero-baseline instance. Otherwise, if `P_low<=60`, retain `max(0,P_low)`. For `P_low>60` and a positive physical reference, award: r = a / C P = min(100, 60 + ln(r)). Here `r` is the improvement factor relative to the physical reference, and `ln` is the natural logarithm with coefficient 1. In the uncapped upper branch, `r = exp(P-60)`: each additional point means an `exp(1)`-fold improvement in the physical objective. The factor is computed from the physical objective and its reference, not from a transformed reward or the old point score. Invalid output retains its existing rejection or zero score; the zero-cost exception applies only after validation. Use one score per file. Both reported ratio channels use points divided by 100. Across official files, take the arithmetic mean. ## Constraints - 1 ≤ N ≤ 1500 - 0 ≤ K ≤ 1500 - Device coordinates: -10000 ≤ x, y ≤ 10000 - All robots (R and S) must be connected in the final network - Relay stations cannot be directly connected to each other ## Time Limit 10 seconds per test case ## Memory Limit 512 MB

结果

Kimi K3.1 ProKimi

max

52.3

平均得分 ↑

  • 52.3采样 1 · 部分分
  • 28.8k平均输出 token(含思考) ↓
  • 31.7输出速度 tokens/s ↑
  • 909 秒延迟 ↓

Kimi K3.1 Pro(high)Kimi high

high

52.3

平均得分 ↑

  • 52.3采样 1 · 部分分
  • 14.2k平均输出 token(含思考) ↓
  • 25.1输出速度 tokens/s ↑
  • 570 秒延迟 ↓

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

52.4

平均得分 ↑

  • 52.4采样 1 · 部分分
  • 57.8k平均输出 token(含思考) ↓
  • 181.2输出速度 tokens/s ↑
  • 319 秒延迟 ↓

MiniMax M3.1 FlashMiniMax

auto(max)

52.3

平均得分 ↑

  • 52.3采样 1 · 部分分
  • 82.2k平均输出 token(含思考) ↓
  • 167.2输出速度 tokens/s ↑
  • 493 秒延迟 ↓

↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。

代码

Kimi K3.1 Pro · 采样 1 · 526 行
#include <bits/stdc++.h>
using namespace std;

using int64 = long long;
const int64 INF = (int64)4e18;

struct Node {
    string id;
    int64 x, y;
    char type;
};

struct Edge {
    int u, v;
};

struct Tree {
    vector<Edge> edges;
    int64 cost = 0;
};

struct DSU {
    vector<int> p, sz;
    explicit DSU(int n = 0) { init(n); }
    void init(int n) {
        p.resize(n);
        sz.assign(n, 1);
        iota(p.begin(), p.end(), 0);
    }
    int find(int x) {
        while (p[x] != x) {
            p[x] = p[p[x]];
            x = p[x];
        }
        return x;
    }
    bool unite(int a, int b) {
        a = find(a);
        b = find(b);
        if (a == b) return false;
        if (sz[a] < sz[b]) swap(a, b);
        p[b] = a;
        sz[a] += sz[b];
        return true;
    }
};

class Solver {
public:
    int N, K, M;
    vector<Node> nodes;
    vector<int64> w;
    vector<vector<int>> starOrder;
    vector<int> relayOrder;
    chrono::steady_clock::time_point startTime;
    Tree best;

    explicit Solver(vector<Node> inputNodes, int n, int k) : N(n), K(k) {
        for (const auto &node : inputNodes)
            if (node.type != 'C') nodes.push_back(node);
        for (const auto &node : inputNodes)
            if (node.type == 'C') nodes.push_back(node);
        M = N + K;
        startTime = chrono::steady_clock::now();
    }

    bool timeUp() const {
        return chrono::duration<double>(chrono::steady_clock::now() - startTime).count() > 8.5;
    }

    inline int64 weight(int u, int v) const {
        return w[(size_t)u * M + v];
    }

    void buildWeights() {
        w.assign((size_t)M * M, 0);
        for (int i = 0; i < M; ++i) {
            for (int j = i + 1; j < M; ++j) {
                int64 value = INF;
                if (!(i >= N && j >= N)) {
                    int64 dx = nodes[i].x - nodes[j].x;
                    int64 dy = nodes[i].y - nodes[j].y;
                    int64 d2 = dx * dx + dy * dy;
                    int factor = 10;
                    if (i < N && j < N &&
                        (nodes[i].type == 'S' || nodes[j].type == 'S'))
                        factor = 8;
                    value = d2 * factor;
                }
                w[(size_t)i * M + j] = value;
                w[(size_t)j * M + i] = value;
            }
        }
    }

    vector<Edge> mst(const vector<int> &vertices, int relayPercent) const {
        int n = (int)vertices.size();
        vector<Edge> result;
        if (n <= 1) return result;

        vector<int64> key(n, INF);
        vector<int> parent(n, -1);
        vector<char> used(n, false);
        key[0] = 0;
        result.reserve(n - 1);

        for (int it = 0; it < n; ++it) {
            int u = -1;
            for (int i = 0; i < n; ++i) {
                if (!used[i] && (u == -1 || key[i] < key[u])) u = i;
            }
            if (u == -1 || key[u] == INF) break;
            used[u] = true;
            if (parent[u] != -1)
                result.push_back({vertices[u], vertices[parent[u]]});

            int gu = vertices[u];
            for (int v = 0; v < n; ++v) {
                if (used[v]) continue;
                int gv = vertices[v];
                int64 value = weight(gu, gv);
                if (value == INF) continue;
                if (relayPercent != 100 && (gu >= N || gv >= N))
                    value = value * relayPercent / 100;
                if (value < key[v]) {
                    key[v] = value;
                    parent[v] = u;
                }
            }
        }
        return result;
    }

    Tree pruneRelayLeaves(const vector<Edge> &edges) const {
        Tree result;
        int E = (int)edges.size();
        if (E == 0) return result;

        struct Arc {
            int to, id, next;
        };
        vector<int> degree(M, 0), head(M, -1), queueVertices;
        vector<Arc> arcs;
        arcs.reserve(2 * E);
        vector<char> removed(E, false);

        for (int i = 0; i < E; ++i) {
            int u = edges[i].u, v = edges[i].v;
            ++degree[u];
            ++degree[v];
            arcs.push_back({v, i, head[u]});
            head[u] = (int)arcs.size() - 1;
            arcs.push_back({u, i, head[v]});
            head[v] = (int)arcs.size() - 1;
        }

        for (int i = N; i < M; ++i)
            if (degree[i] == 1) queueVertices.push_back(i);

        for (size_t q = 0; q < queueVertices.size(); ++q) {
            int u = queueVertices[q];
            if (degree[u] != 1) continue;
            for (int a = head[u]; a != -1; a = arcs[a].next) {
                int id = arcs[a].id;
                if (removed[id]) continue;
                removed[id] = true;
                int v = arcs[a].to;
                --degree[u];
                --degree[v];
                if (v >= N && degree[v] == 1) queueVertices.push_back(v);
                break;
            }
        }

        result.edges.reserve(E);
        for (int i = 0; i < E; ++i) {
            if (!removed[i]) {
                result.edges.push_back(edges[i]);
                result.cost += weight(edges[i].u, edges[i].v);
            }
        }
        return result;
    }

    int activeRelayCount(const Tree &t) const {
        vector<char> active(K, false);
        int count = 0;
        for (const auto &e : t.edges) {
            if (e.u >= N && !active[e.u - N]) {
                active[e.u - N] = true;
                ++count;
            }
            if (e.v >= N && !active[e.v - N]) {
                active[e.v - N] = true;
                ++count;
            }
        }
        return count;
    }

    Tree normalize(Tree t) const {
        for (int iteration = 0; iteration < 4; ++iteration) {
            vector<char> active(K, false);
            for (const auto &e : t.edges) {
                if (e.u >= N) active[e.u - N] = true;
                if (e.v >= N) active[e.v - N] = true;
            }

            vector<int> vertices(N);
            iota(vertices.begin(), vertices.end(), 0);
            int oldActive = 0;
            for (int c = 0; c < K; ++c) {
                if (active[c]) {
                    vertices.push_back(N + c);
                    ++oldActive;
                }
            }

            Tree next = pruneRelayLeaves(mst(vertices, 100));
            if (next.cost > t.cost) break;
            int newActive = activeRelayCount(next);
            t = std::move(next);
            if (newActive >= oldActive) break;
        }
        return t;
    }

    void buildRelayOrders() {
        starOrder.assign(K, {});
        vector<int64> score(K, 0);

        for (int c = 0; c < K; ++c) {
            int g = N + c;
            starOrder[c].resize(N);
            iota(starOrder[c].begin(), starOrder[c].end(), 0);
            sort(starOrder[c].begin(), starOrder[c].end(), [&](int a, int b) {
                int64 wa = weight(g, a), wb = weight(g, b);
                if (wa != wb) return wa < wb;
                return a < b;
            });
            if (N >= 2)
                score[c] = weight(g, starOrder[c][0]) + weight(g, starOrder[c][1]);
            else if (N == 1)
                score[c] = weight(g, starOrder[c][0]);
        }

        relayOrder.resize(K);
        iota(relayOrder.begin(), relayOrder.end(), 0);
        sort(relayOrder.begin(), relayOrder.end(), [&](int a, int b) {
            if (score[a] != score[b]) return score[a] < score[b];
            return a < b;
        });
    }

    bool insertionPass(Tree &current, const vector<int> &order) {
        bool improved = false;
        vector<char> active(M, false);
        for (const auto &e : current.edges) {
            if (e.u >= N) active[e.u] = true;
            if (e.v >= N) active[e.v] = true;
        }

        vector<Edge> sortedTree = current.edges;
        auto sortTree = [&]() {
            sort(sortedTree.begin(), sortedTree.end(), [&](const Edge &a, const Edge &b) {
                int64 wa = weight(a.u, a.v), wb = weight(b.u, b.v);
                if (wa != wb) return wa < wb;
                if (a.u != b.u) return a.u < b.u;
                return a.v < b.v;
            });
        };
        sortTree();

        for (int c : order) {
            if (timeUp() || current.cost == 0) break;
            int g = N + c;
            if (active[g]) continue;

            DSU dsu(M);
            int target = (int)current.edges.size() + 1;
            int selected = 0;
            size_t i = 0;
            int j = 0;
            vector<Edge> candidateEdges;
            candidateEdges.reserve(target);

            while (selected < target &&
                   (i < sortedTree.size() || j < N)) {
                Edge e;
                if (i >= sortedTree.size()) {
                    e = {g, starOrder[c][j++]};
                } else if (j >= N) {
                    e = sortedTree[i++];
                } else {
                    int64 treeW = weight(sortedTree[i].u, sortedTree[i].v);
                    int64 starW = weight(g, starOrder[c][j]);
                    if (treeW <= starW) e = sortedTree[i++];
                    else e = {g, starOrder[c][j++]};
                }

                if (dsu.unite(e.u, e.v)) {
                    candidateEdges.push_back(e);
                    ++selected;
                }
            }

            if (selected != target) continue;
            Tree candidate = pruneRelayLeaves(candidateEdges);
            if (candidate.cost < current.cost) {
                current = std::move(candidate);
                improved = true;

                fill(active.begin(), active.end(), false);
                for (const auto &e : current.edges) {
                    if (e.u >= N) active[e.u] = true;
                    if (e.v >= N) active[e.v] = true;
                }
                sortedTree = current.edges;
                sortTree();
            }
        }
        return improved;
    }

    vector<Edge> connectNeighbors(const vector<int> &neighbors) const {
        int d = (int)neighbors.size();
        vector<Edge> added;
        if (d <= 1) return added;

        vector<int64> key(d, INF);
        vector<int> parent(d, -1);
        vector<char> used(d, false);
        key[0] = 0;
        added.reserve(d - 1);

        for (int it = 0; it < d; ++it) {
            int u = -1;
            for (int i = 0; i < d; ++i)
                if (!used[i] && (u == -1 || key[i] < key[u])) u = i;
            used[u] = true;
            if (parent[u] != -1)
                added.push_back({neighbors[u], neighbors[parent[u]]});

            for (int v = 0; v < d; ++v) {
                if (used[v]) continue;
                int64 value = weight(neighbors[u], neighbors[v]);
                if (value < key[v]) {
                    key[v] = value;
                    parent[v] = u;
                }
            }
        }
        return added;
    }

    bool deletionPass(Tree &current, const vector<int> &order) {
        bool improved = false;
        vector<char> active(M, false);
        for (const auto &e : current.edges) {
            if (e.u >= N) active[e.u] = true;
            if (e.v >= N) active[e.v] = true;
        }

        for (int c : order) {
            if (timeUp() || current.cost == 0) break;
            int g = N + c;
            if (!active[g]) continue;

            vector<Edge> remaining;
            vector<int> neighbors;
            remaining.reserve(current.edges.size());

            for (const auto &e : current.edges) {
                if (e.u == g || e.v == g) {
                    neighbors.push_back(e.u == g ? e.v : e.u);
                } else {
                    remaining.push_back(e);
                }
            }
            if (neighbors.empty()) continue;

            vector<Edge> added = connectNeighbors(neighbors);
            remaining.insert(remaining.end(), added.begin(), added.end());
            Tree candidate = pruneRelayLeaves(remaining);

            if (candidate.cost < current.cost) {
                current = std::move(candidate);
                improved = true;
                fill(active.begin(), active.end(), false);
                for (const auto &e : current.edges) {
                    if (e.u >= N) active[e.u] = true;
                    if (e.v >= N) active[e.v] = true;
                }
            }
        }
        return improved;
    }

    Tree localSearch(Tree current, const vector<int> &order) {
        current = normalize(current);
        for (int round = 0; round < 5 && !timeUp() && current.cost > 0; ++round) {
            int64 before = current.cost;
            insertionPass(current, order);
            if (!timeUp()) current = normalize(current);
            if (!timeUp()) {
                deletionPass(current, order);
                current = normalize(current);
            }
            if (current.cost >= before) break;
        }
        return current;
    }

    void updateBest(const Tree &t) {
        if (t.cost < best.cost ||
            (t.cost == best.cost && t.edges.size() < best.edges.size()))
            best = t;
    }

    void solve() {
        buildWeights();

        vector<int> robots(N);
        iota(robots.begin(), robots.end(), 0);
        Tree base = pruneRelayLeaves(mst(robots, 100));
        best = base;

        if (base.cost == 0 || K == 0) return;

        buildRelayOrders();

        Tree initial = localSearch(base, relayOrder);
        updateBest(initial);
        if (best.cost == 0) return;

        vector<Tree> seeds;
        vector<int> allVertices(M);
        iota(allVertices.begin(), allVertices.end(), 0);
        const int percentages[] = {65, 80, 100, 115, 135, 165, 220};

        for (int percent : percentages) {
            if (timeUp()) break;
            Tree seed = pruneRelayLeaves(mst(allVertices, percent));
            seed = normalize(seed);
            updateBest(seed);
            seeds.push_back(std::move(seed));
        }

        if (!timeUp() && K >= 3) {
            int choices[2] = {K / 3, 2 * K / 3};
            for (int q : choices) {
                if (q <= 0 || timeUp()) continue;
                vector<int> vertices = robots;
                for (int i = 0; i < q; ++i)
                    vertices.push_back(N + relayOrder[i]);
                Tree seed = pruneRelayLeaves(mst(vertices, 100));
                seed = normalize(seed);
                updateBest(seed);
                seeds.push_back(std::move(seed));
            }
        }

        sort(seeds.begin(), seeds.end(), [](const Tree &a, const Tree &b) {
            if (a.cost != b.cost) return a.cost < b.cost;
            return a.edges.size() < b.edges.size();
        });

        int usedSeeds = 0;
        for (const auto &seed : seeds) {
            if (usedSeeds >= 4 || timeUp() || best.cost == 0) break;
            Tree candidate = localSearch(seed, relayOrder);
            updateBest(candidate);
            ++usedSeeds;
        }

        mt19937 rng(123456789);
        for (int attempt = 0; attempt < 3 && !timeUp() && best.cost > 0; ++attempt) {
            vector<int> randomOrder = relayOrder;
            shuffle(randomOrder.begin(), randomOrder.end(), rng);
            Tree candidate = localSearch(base, randomOrder);
            updateBest(candidate);
        }
    }

    void output() const {
        vector<char> selected(K, false);
        for (const auto &e : best.edges) {
            if (e.u >= N) selected[e.u - N] = true;
            if (e.v >= N) selected[e.v - N] = true;
        }

        bool any = false, first = true;
        for (int c = 0; c < K; ++c) {
            if (!selected[c]) continue;
            any = true;
            if (!first) cout << '#';
            first = false;
            cout << nodes[N + c].id;
        }
        if (!any) cout << '#';
        cout << '\n';

        for (size_t i = 0; i < best.edges.size(); ++i) {
            if (i) cout << '#';
            cout << nodes[best.edges[i].u].id << '-'
                 << nodes[best.edges[i].v].id;
        }
        cout << '\n';
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, K;
    cin >> N >> K;
    vector<Node> input(N + K);
    for (int i = 0; i < N + K; ++i)
        cin >> input[i].id >> input[i].x >> input[i].y >> input[i].type;

    Solver solver(input, N, K);
    solver.solve();
    solver.output();
    return 0;
}