题目 › fcs-239

FrontierCS #239

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

查看原题跳到结果

题面

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

Problem Description: You are given a directed graph G on vertices numbered $0$ to $n$. Initially, G contains exactly n edges of the form $v → v + 1$. Your task is to add some edges to this graph in such a way that for every two vertices $v, u (v < u)$ there exists a directed path from v to u consisting of at most three edges. You can add an edge $a → c$ if and only if there exists such $b$ that edges $a → b$ and $b → c$ are already present in $G$. find the minimum edges you need to add such that for every two vertices $v, u (v < u)$ there exists a directed path from v to u consisting of at most three edges Input Input a single line contains a single integer $n(0\leq n \leq 2^{12})$ Output First line contains a single integer $m$ Following $m$ lines, each line contains a three integer $u, c, v$, representing there is an edge from $u$ to $c$, and an edge from $c$ to v, you add an edge from $u$ to $v$ Example 1: Input: 5 Output: 2 2 3 4 1 2 4 Scoring: The physical objective is number of added shortcut edges m; smaller is better. The physical reference is `a = m_ref`; matching a positive reference earns 60 points. Define the historical low-score expression (in points): P_low = 60*max(0,(3*m_ref-m)/(2*m_ref)). A valid solution with `m=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 / m 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. If m_ref=0, a valid zero-edge construction receives 100 and a positive edge count receives 0. Time limit: 2 seconds Memory limit: 512 MB

结果

Kimi K3.1 ProKimi

max

54.9

平均得分 ↑

  • 54.9采样 1 · 部分分
  • 47.5k平均输出 token(含思考) ↓
  • 26.0输出速度 tokens/s ↑
  • 1827 秒延迟 ↓

Kimi K3.1 Pro(high)Kimi high

high

45.7

平均得分 ↑

  • 45.7采样 1 · 部分分
  • 38.1k平均输出 token(含思考) ↓
  • 28.7输出速度 tokens/s ↑
  • 1328 秒延迟 ↓

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

0.0

平均得分 ↑

  • 0.0采样 1 · 答案错误
  • 156.6k平均输出 token(含思考) ↓
  • 192.1输出速度 tokens/s ↑
  • 816 秒延迟 ↓

MiniMax M3.1 FlashMiniMax

auto(max)

59.6

平均得分 ↑

  • 59.6采样 1 · 部分分
  • 97.9k平均输出 token(含思考) ↓
  • 111.4输出速度 tokens/s ↑
  • 880 秒延迟 ↓

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

代码

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

struct Builder {
    int n, N, mode;
    vector<vector<unsigned char>> adj;
    vector<vector<int>> out;
    vector<array<int, 3>> ops;

    Builder(int n_, int mode_) : n(n_), N(n_ + 1), mode(mode_) {
        adj.assign(N, vector<unsigned char>(N, 0));
        out.assign(N, {});
        for (int i = 0; i < n; ++i) {
            adj[i][i + 1] = 1;
            out[i].push_back(i + 1);
        }
    }

    void addEdge(int a, int b, int c) {
        if (adj[a][c]) return;
        adj[a][c] = 1;
        out[a].push_back(c);
        ops.push_back({a, b, c});
    }

    bool withinTwo(int v, int t) {
        if (adj[v][t]) return true;
        for (int b : out[v]) {
            if (b < t && adj[b][t]) return true;
        }
        return false;
    }

    bool findTwoPath(int v, int t, int &mid) {
        for (int b : out[v]) {
            if (b < t && adj[b][t]) {
                mid = b;
                return true;
            }
        }
        return false;
    }

    int leftSize(int L) {
        int a;
        if (mode == 0) {
            a = (L + 1) / 2;
        } else if (mode == 1) {
            a = (2 * L + 2) / 3;
        } else if (mode == 2) {
            a = (7 * L + 9) / 10;
        } else if (mode == 3) {
            a = (3 * L + 3) / 4;
        } else {
            if (L <= 32) a = L - 3;
            else a = (7 * L + 9) / 10;
        }
        return max(1, min(L - 1, a));
    }

    void solve(int l, int r) {
        int L = r - l;
        if (L <= 3) return;

        if (L == 4) {
            addEdge(l + 2, l + 3, l + 4);
            return;
        }

        if (L <= 8) {
            int h = l + 4;
            addEdge(h - 2, h - 1, h);
            addEdge(h - 3, h - 2, h);
            for (int c = h + 2; c <= r; ++c) {
                addEdge(h, c - 1, c);
            }
            return;
        }

        int a = leftSize(L);
        int h = l + a;

        solve(l, h);
        solve(h, r);

        for (int u = h + 2; u <= r; ++u) {
            if (!adj[h][u]) addEdge(h, u - 1, u);
        }

        for (int v = h - 1; v >= l; --v) {
            if (withinTwo(v, h)) continue;
            int src = v + 1;
            int mid = -1;
            findTwoPath(src, h, mid);
            addEdge(src, mid, h);
        }
    }
};

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

    int n;
    cin >> n;

    vector<array<int, 3>> best;
    bool first = true;

    for (int mode = 0; mode < 5; ++mode) {
        Builder builder(n, mode);
        builder.solve(0, n);
        if (first || builder.ops.size() < best.size()) {
            best = builder.ops;
            first = false;
        }
    }

    cout << best.size() << '\n';
    for (auto &op : best) {
        cout << op[0] << ' ' << op[1] << ' ' << op[2] << '\n';
    }
    return 0;
}