题面
来源: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; }
Kimi K3.1 Pro(high) · 采样 1 · 117 行
#include <bits/stdc++.h> using namespace std; struct Op { int a, b, c; }; int n; vector<int> dp, choice; vector<Op> answer; set<pair<int, int>> added; void addEdge(int a, int b, int c) { if (added.count({a, c})) return; added.insert({a, c}); answer.push_back({a, b, c}); } void solveBase5(int l) { const vector<vector<Op>> candidates = { {{0, 1, 2}, {2, 3, 4}}, {{2, 3, 4}, {1, 2, 4}}, {{1, 2, 3}, {1, 3, 4}}, {{0, 1, 2}, {3, 4, 5}}, {{1, 2, 3}, {3, 4, 5}} }; int best = 0, bestMissing = INT_MAX; for (int i = 0; i < (int)candidates.size(); ++i) { int missing = 0; for (const Op &op : candidates[i]) { if (!added.count({l + op.a, l + op.c})) ++missing; } if (missing < bestMissing) { bestMissing = missing; best = i; } } for (const Op &op : candidates[best]) { addEdge(l + op.a, l + op.b, l + op.c); } } void solve(int l, int r) { int len = r - l; if (len <= 3) return; if (len == 4) { if (added.count({l, l + 2}) || added.count({l + 2, r})) return; addEdge(l, l + 1, l + 2); return; } if (len == 5) { solveBase5(l); return; } int leftLen = choice[len]; int A = l + leftLen; int B = A + 4; for (int u = A - 2; u >= l; --u) { addEdge(u, u + 1, A); } for (int v = B + 2; v <= r; ++v) { addEdge(B, v - 1, v); } addEdge(A + 1, A + 2, A + 3); addEdge(A + 1, A + 3, B); addEdge(A, A + 1, B); solve(l, A); solve(B, r); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; dp.assign(n + 1, 0); choice.assign(n + 1, 0); if (n >= 4) dp[4] = 1; if (n >= 5) dp[5] = 2; for (int len = 6; len <= n; ++len) { int best = INT_MAX; int bestLeft = 1; for (int left = 1; left <= len - 5; ++left) { int right = len - 4 - left; int current = len - 3 + dp[left] + dp[right]; if (current < best) { best = current; bestLeft = left; } } dp[len] = best; choice[len] = bestLeft; } if (n >= 4) solve(0, n); cout << answer.size() << '\n'; for (const Op &op : answer) { cout << op.a << ' ' << op.b << ' ' << op.c << '\n'; } return 0; }
DeepSeek Flash V4.1-1017 · 采样 1 · 167 行
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int dp[4097][64]; struct Recon { int k, p1, p2, flag; } recon[4097][64]; vector<int> profiles[4097]; int encode(int a, int b, int c) { return a * 16 + b * 4 + c; } void build(int L, int l, int p, vector<tuple<int,int,int>>& edges) { if (L == 0) return; if (L <= 3) { int a = p / 16, b = (p / 4) % 4, c = p % 4; if (L == 1) { // no edges } else if (L == 2) { if (a == 2 && b == 2 && c == 2) { // no edges } else if (a == 1 && b == 1 && c == 1) { edges.emplace_back(l, l + 1, l + 2); } } else if (L == 3) { if (a == 3 && b == 3 && c == 3) { // no edges } else if (a == 2 && b == 2 && c == 2) { edges.emplace_back(l, l + 1, l + 2); } else if (a == 1 && b == 1 && c == 2) { edges.emplace_back(l, l + 1, l + 2); edges.emplace_back(l, l + 2, l + 3); } else if (a == 1 && b == 2 && c == 1) { edges.emplace_back(l + 1, l + 2, l + 3); edges.emplace_back(l, l + 1, l + 3); } else if (a == 1 && b == 1 && c == 1) { edges.emplace_back(l, l + 1, l + 2); edges.emplace_back(l + 1, l + 2, l + 3); edges.emplace_back(l, l + 2, l + 3); } } return; } int k = recon[L][p].k; int p1 = recon[L][p].p1; int p2 = recon[L][p].p2; int flag = recon[L][p].flag; build(k, l, p1, edges); build(L - k, l + k, p2, edges); if (flag == 1) { edges.emplace_back(l, l + k, l + L); } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; if (n == 0) { cout << 0 << "\n"; return 0; } for (int i = 0; i <= n; ++i) for (int j = 0; j < 64; ++j) dp[i][j] = INF; // Base cases int p = encode(1, 1, 1); dp[1][p] = 0; profiles[1].push_back(p); p = encode(2, 2, 2); dp[2][p] = 0; profiles[2].push_back(p); p = encode(1, 1, 1); dp[2][p] = 1; profiles[2].push_back(p); p = encode(3, 3, 3); dp[3][p] = 0; profiles[3].push_back(p); p = encode(2, 2, 2); dp[3][p] = 1; profiles[3].push_back(p); p = encode(1, 1, 2); dp[3][p] = 2; profiles[3].push_back(p); p = encode(1, 2, 1); dp[3][p] = 2; profiles[3].push_back(p); p = encode(1, 1, 1); dp[3][p] = 3; profiles[3].push_back(p); int combine[64][64]; int add_combine[64][64]; for (int p1 = 0; p1 < 64; ++p1) { int a1 = p1 / 16, b1 = (p1 / 4) % 4, c1 = p1 % 4; for (int p2 = 0; p2 < 64; ++p2) { int a2 = p2 / 16, b2 = (p2 / 4) % 4, c2 = p2 % 4; combine[p1][p2] = -1; add_combine[p1][p2] = -1; if (c1 + b2 <= 3) { int na = min(4, a1 + a2); int nb = min(4, max(b1, a1 + b2)); int nc = min(4, max(c2, c1 + a2)); if (na <= 3 && nb <= 3 && nc <= 3) { combine[p1][p2] = na * 16 + nb * 4 + nc; } if (a1 == 1 && a2 == 1) { int na2 = 1; int nb2 = min(4, max(b1, a1 + b2)); int nc2 = min(4, max(c2, c1 + a2)); if (nb2 <= 3 && nc2 <= 3) { add_combine[p1][p2] = na2 * 16 + nb2 * 4 + nc2; } } } } } for (int L = 4; L <= n; ++L) { for (int k = 1; k < L; ++k) { int L1 = k, L2 = L - k; for (int p1 : profiles[L1]) { int cost1 = dp[L1][p1]; for (int p2 : profiles[L2]) { int cost2 = dp[L2][p2]; int newp = combine[p1][p2]; if (newp != -1) { int cost = cost1 + cost2; if (cost < dp[L][newp]) { dp[L][newp] = cost; recon[L][newp] = {k, p1, p2, 0}; } } newp = add_combine[p1][p2]; if (newp != -1) { int cost = cost1 + cost2 + 1; if (cost < dp[L][newp]) { dp[L][newp] = cost; recon[L][newp] = {k, p1, p2, 1}; } } } } } for (int p = 0; p < 64; ++p) { if (dp[L][p] < INF) { profiles[L].push_back(p); } } } int best_p = -1; int best_cost = INF; for (int p : profiles[n]) { if (dp[n][p] < best_cost) { best_cost = dp[n][p]; best_p = p; } } if (best_p == -1) return 0; vector<tuple<int,int,int>> edges; build(n, 0, best_p, edges); cout << edges.size() << "\n"; for (auto &e : edges) { cout << get<0>(e) << " " << get<1>(e) << " " << get<2>(e) << "\n"; } return 0; }
MiniMax M3.1 Flash · 采样 1 · 230 行
#include <bits/stdc++.h> using namespace std; struct Addition { int u, c, v; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; const int N = n + 1; const int INF = 1'000'000'000; const int MAXK = 10; vector<int> baseCost(N + 1, INF); for (int s = 0; s <= min(N, 4); ++s) baseCost[s] = 0; if (N >= 5) baseCost[5] = 1; if (N >= 6) baseCost[6] = 2; if (N >= 7) baseCost[7] = 3; if (N >= 8) baseCost[8] = 4; if (N >= 9) baseCost[9] = 5; if (N >= 10) baseCost[10] = 6; vector<int> best(N + 1, INF); vector<int> chosenK(N + 1, -1); vector<vector<int>> A(MAXK + 1, vector<int>(N + 1, INF)); vector<vector<int>> aChoice(MAXK + 1, vector<int>(N + 1, -1)); vector<vector<int>> dChoice(MAXK + 1, vector<int>(N + 1, -1)); vector<int> endCost(N + 1, 0); vector<int> middleCost(N + 1, 0); for (int s = 0; s <= N; ++s) { if (baseCost[s] < INF) best[s] = baseCost[s]; for (int k = 2; k <= min(MAXK, s + 1); ++k) { int separators = k - 1; int r = s - separators; int value = INF; int arg = 0; const auto &prev = A[k - 1]; for (int x = 0; x <= r; ++x) { int candidate = prev[r - x] + endCost[x]; if (candidate < value) { value = candidate; arg = x; } } dChoice[k][r] = arg; int candidate = value + separators * (separators - 1) / 2; if (candidate < best[s]) { best[s] = candidate; chosenK[s] = k; } } endCost[s] = best[s] + s - (s > 0 ? 1 : 0); middleCost[s] = best[s] + 2 * s - (s > 0 ? 2 : 1); A[1][s] = endCost[s]; for (int k = 2; k <= MAXK; ++k) { int value = INF; int arg = 0; const auto &prev = A[k - 1]; for (int x = 0; x <= s; ++x) { int candidate = prev[s - x] + middleCost[x]; if (candidate < value) { value = candidate; arg = x; } } A[k][s] = value; aChoice[k][s] = arg; } } function<vector<int>(int, int)> reconstructA = [&](int k, int total) -> vector<int> { if (k == 1) return {total}; int x = aChoice[k][total]; vector<int> result = reconstructA(k - 1, total - x); result.push_back(x); return result; }; vector<Addition> additions; auto add = [&](int u, int c, int v) { additions.push_back({u, c, v}); }; auto addBase = [&](int offset, int size) { auto addRelative = [&](int u, int c, int v) { add(offset + u, offset + c, offset + v); }; switch (size) { case 5: addRelative(1, 2, 3); break; case 6: addRelative(2, 3, 4); addRelative(1, 2, 4); break; case 7: addRelative(2, 3, 4); addRelative(1, 2, 4); addRelative(4, 5, 6); break; case 8: addRelative(1, 2, 3); addRelative(3, 4, 5); addRelative(1, 3, 5); addRelative(5, 6, 7); break; case 9: addRelative(1, 2, 3); addRelative(3, 4, 5); addRelative(1, 3, 5); addRelative(5, 6, 7); addRelative(5, 7, 8); break; case 10: addRelative(1, 2, 3); addRelative(3, 4, 5); addRelative(1, 3, 5); addRelative(5, 6, 7); addRelative(5, 7, 8); addRelative(5, 8, 9); break; default: break; } }; function<void(int, int)> build = [&](int offset, int size) { if (size == 0) return; int k = chosenK[size]; if (k == -1) { addBase(offset, size); return; } int separators = k - 1; int r = size - separators; int last = dChoice[k][r]; vector<int> childSizes = reconstructA(k - 1, r - last); childSizes.push_back(last); vector<int> childLeft(k), childRight(k); vector<int> sep(separators); int pos = offset; for (int j = 0; j < k; ++j) { childLeft[j] = pos; childRight[j] = pos + childSizes[j] - 1; pos += childSizes[j]; if (j < separators) { sep[j] = pos; ++pos; } } for (int j = 0; j < k; ++j) { build(childLeft[j], childSizes[j]); if (j < separators) { for (int x = childLeft[j]; x <= childRight[j]; ++x) { if (sep[j] - x > 1) { add(x, x + 1, sep[j]); } } } if (j > 0) { for (int x = childLeft[j]; x <= childRight[j]; ++x) { if (x - sep[j - 1] > 1) { add(sep[j - 1], x - 1, x); } } } } for (int a = 0; a < separators; ++a) { for (int b = a + 1; b < separators; ++b) { if (sep[b] - sep[a] == 1) continue; if (b == a + 1) { add(sep[a], sep[a] + 1, sep[b]); } else { add(sep[a], sep[a + 1], sep[b]); } } } }; build(0, N); sort(additions.begin(), additions.end(), [](const Addition &a, const Addition &b) { int da = a.v - a.u; int db = b.v - b.u; if (da != db) return da < db; if (a.u != b.u) return a.u < b.u; return a.v < b.v; }); cout << additions.size() << '\n'; for (const auto &e : additions) { cout << e.u << ' ' << e.c << ' ' << e.v << '\n'; } return 0; }