题面
来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。
Problem: Hedgehog Graph
Time limit: 5 seconds
Memory limit: 1024 megabytes
This is an interactive problem.
A hedgehog graph is a directed graph where each vertex has exactly one outgoing edge and contains exactly one directed cycle of length at least 3 (the graph does not contain a loop or cycle of length 2).
For every edge e = u -> v in the hedgehog graph, v belongs to the aforementioned single directed cycle.
For a vertex v, if there exists an edge v -> w we denote the vertex w = next(v) as the next vertex. This vertex exists and is unique.
Kipa has n hedgehog graphs with 10^6 vertices. Each vertex is numbered from 1 to 10^6.
Kipa is not given the graph directly. Instead, Kipa can ask queries to explore the graph.
Your task is to help Kipa determine the length of the directed cycle for each hedgehog graph.
Interaction Protocol
First, your program must read from the standard input one line with the positive integer n, the number of graphs to process. n will be at most 10.
For each graph, the program can ask the following query at most 2500 times:
? v x
Given a vertex v and a positive integer x, the jury starts at v, moves to the next vertex x times, and returns the index of the resulting vertex.
(1 <= v <= 10^6, 1 <= x <= 5 * 10^18)
Once you have determined the length of the cycle s, output:
! s
After that, read a single integer which is either:
1, if the answer is correct. You should immediately start processing the next graph, or finish your program with the exit code 0 if all n graphs are processed.
-1, if the answer is incorrect. In this case, you should finish your program with exit code 0, in which case you will receive a Wrong Answer verdict.
Failure to handle this properly may result in unexpected behavior. You must flush your output after every interaction.
The interactor is adaptive. The interactor does not necessarily start with a fixed graph at the beginning of the interaction. It only guarantees that there exists at least one hedgehog graph that satisfies all the provided responses and the input specification.
Example Input:
1
3
7
10
1
Example Output:
? 1 2
? 2 5
? 10 11
! 11
Scoring
The physical objective is per-graph query count Q_j; smaller is better. The physical reference is `a = 500`; matching a positive reference earns 60 points.
Define the historical low-score expression (in points):
P_low = 60*max(0,(2500-Q_j)/2000)^2.
A valid solution with `Q_j=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 / Q_j
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. Apply this mapping to each internal case, then average the points. Both reported ratio channels use points divided by 100. Across official files, take the arithmetic mean.
结果
Kimi K3.1 ProKimi
max
9.3
平均得分 ↑
- 9.3采样 1 · 部分分
- 56.8k平均输出 token(含思考) ↓
- 28.6输出速度 tokens/s ↑
- 1988 秒延迟 ↓
Kimi K3.1 Pro(high)Kimi high
high
9.3
平均得分 ↑
- 9.3采样 1 · 部分分
- 3.8k平均输出 token(含思考) ↓
- 23.5输出速度 tokens/s ↑
- 165 秒延迟 ↓
DeepSeek Flash V4.1-1017DeepSeek
auto(high)
9.3
平均得分 ↑
- 9.3采样 1 · 部分分
- 24.5k平均输出 token(含思考) ↓
- 167.5输出速度 tokens/s ↑
- 147 秒延迟 ↓
MiniMax M3.1 FlashMiniMax
auto(max)
0.0
平均得分 ↑
- 0.0采样 1 · 超时
- 97.5k平均输出 token(含思考) ↓
- 84.2输出速度 tokens/s ↑
- 1159 秒延迟 ↓
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
Kimi K3.1 Pro · 采样 1 · 83 行
#include <bits/stdc++.h> using namespace std; int ask(int v, long long x) { cout << "? " << v << " " << x << '\n' << flush; int response; cin >> response; return response; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; if (!(cin >> n)) return 0; for (int tc = 0; tc < n; ++tc) { int start = ask(1, 1); vector<int> cache(1025, -1); cache[0] = start; auto getValue = [&](int x) -> int { if (cache[x] == -1) cache[x] = ask(start, x); return cache[x]; }; auto attempt = [&](int baby, int giants) -> int { unordered_map<int, int> position; position.reserve(2 * baby + 10); for (int i = 0; i < baby; ++i) { int w = getValue(i); auto it = position.find(w); if (it != position.end()) return i - it->second; position.emplace(w, i); } for (int k = 1; k <= giants; ++k) { int x = k * baby; int w = getValue(x); auto it = position.find(w); if (it != position.end()) return x - it->second; } return -1; }; int answer = attempt(2, 4); if (answer == -1) answer = attempt(8, 4); if (answer == -1) answer = attempt(32, 32); if (answer == -1) { unordered_map<int, int> position; position.reserve(2048); for (int i = 0; i < 1000; ++i) { int w = getValue(i); auto it = position.find(w); if (it != position.end()) { answer = i - it->second; break; } position.emplace(w, i); } int k = 2; while (answer == -1) { int x = k * 1000; int w = ask(start, x); auto it = position.find(w); if (it != position.end()) answer = x - it->second; ++k; } } cout << "! " << answer << '\n' << flush; int verdict; if (!(cin >> verdict) || verdict == -1) return 0; } return 0; }
Kimi K3.1 Pro(high) · 采样 1 · 68 行
#include <bits/stdc++.h> using namespace std; static const int MAXV = 1000000; static const int B = 1000; long long ask(long long v, long long x) { cout << "? " << v << " " << x << endl; cout.flush(); long long res; if (!(cin >> res)) exit(0); return res; } bool answer(long long s) { cout << "! " << s << endl; cout.flush(); int verdict; if (!(cin >> verdict)) exit(0); return verdict == 1; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; if (!(cin >> n)) return 0; vector<int> seen(MAXV + 1, -1); for (int g = 0; g < n; ++g) { long long a = ask(1, 1); long long s = -1; seen[a] = 0; for (int i = 1; i <= B; ++i) { long long r = ask(a, i); if (r == a) { s = i; break; } seen[r] = i; } if (s == -1) { for (long long j = 2; ; ++j) { long long x = j * B; long long r = ask(a, x); if (seen[r] != -1) { s = x - seen[r]; break; } } } if (!answer(s)) return 0; seen[a] = -1; for (int i = 1; i <= min<long long>(B, s - 1); ++i) { // Entries are cleared below by reconstructing only when necessary. } fill(seen.begin(), seen.end(), -1); } return 0; }
DeepSeek Flash V4.1-1017 · 采样 1 · 64 行
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; if (!(cin >> n)) return 0; const int MAXV = 1000000; const int B = 1000; vector<int> pos(MAXV + 1, -1); for (int graph = 0; graph < n; ++graph) { fill(pos.begin(), pos.end(), -1); cout << "? 1 1" << endl; int c; cin >> c; pos[c] = 0; bool done = false; int ans = -1; for (int i = 1; i < B; ++i) { cout << "? " << c << " " << i << endl; int r; cin >> r; if (r == c) { ans = i; done = true; break; } pos[r] = i; } if (!done) { int maxj = (MAXV + B - 1) / B; for (int j = 1; j <= maxj; ++j) { long long x = 1LL * j * B; cout << "? " << c << " " << x << endl; int r; cin >> r; if (pos[r] != -1) { ans = (int)(x - pos[r]); break; } } } cout << "! " << ans << endl; int ok; cin >> ok; if (ok == -1) return 0; } return 0; }
MiniMax M3.1 Flash · 采样 1 · 170 行
#include <bits/stdc++.h> using namespace std; using int64 = long long; constexpr int MAX_VERTEX = 1'000'000; constexpr int QUERY_LIMIT = 2500; constexpr int EXTRACTION_RESERVE = 32; constexpr int EXPONENT_RANGE = 1'000'000'000; static int firstExponent[MAX_VERTEX + 1]; int64 randomExponent(mt19937_64& rng) { return uniform_int_distribution<int>(1, EXPONENT_RANGE)(rng); } vector<pair<int64, int>> factorSmallPrimes(int64 value) { vector<pair<int64, int>> factors; int64 remaining = value; for (int64 p = 2; p * p <= remaining; ++p) { if (remaining % p != 0) continue; int exponent = 0; do { remaining /= p; ++exponent; } while (remaining % p == 0); if (p <= MAX_VERTEX) { factors.emplace_back(p, exponent); } } if (remaining > 1 && remaining <= MAX_VERTEX) { factors.emplace_back(remaining, 1); } return factors; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; if (!(cin >> n)) return 0; uint64_t seed = chrono::high_resolution_clock::now().time_since_epoch().count(); seed ^= uint64_t(random_device{}()) << 32; mt19937_64 rng(seed); int queries = 0; auto ask = [&](int vertex, int64 exponent) -> int { cout << "? " << vertex << ' ' << exponent << endl; if (!(cin >> queries)) { exit(0); } ++queries; int result; if (!(cin >> result)) exit(0); return result; }; auto recoverPeriod = [&](int64 multiple, int cycleVertex) -> int64 { auto factors = factorSmallPrimes(multiple); int64 answer = 1; for (auto [prime, exponent] : factors) { int64 fullPower = 1; for (int i = 0; i < exponent; ++i) { fullPower *= prime; } int64 remainingMultiple = multiple / fullPower; int low = 0; int high = exponent; while (low < high) { int mid = (low + high) / 2; int64 primePower = 1; for (int i = 0; i < mid; ++i) { primePower *= prime; } int64 testExponent = remainingMultiple * primePower; bool isPeriod = (ask(cycleVertex, testExponent) == cycleVertex); if (isPeriod) { high = mid; } else { low = mid + 1; } } for (int i = 0; i < low; ++i) { answer *= prime; } } return answer; }; while (n--) { fill(firstExponent, firstExponent + MAX_VERTEX + 1, -1); int cycleVertex = ask(1, 1); firstExponent[cycleVertex] = 0; int64 difference = 0; while (difference == 0 && queries < QUERY_LIMIT - EXTRACTION_RESERVE) { int64 exponent = randomExponent(rng); int result = ask(cycleVertex, exponent); if (firstExponent[result] == -1) { firstExponent[result] = static_cast<int>(exponent); } else { int64 previous = firstExponent[result]; if (previous != exponent) { difference = exponent > previous ? exponent - previous : previous - exponent; } } } if (difference == 0) { int64 exponent = randomExponent(rng); int result = ask(cycleVertex, exponent); if (firstExponent[result] != -1) { int64 previous = firstExponent[result]; if (previous != exponent) { difference = exponent > previous ? exponent - previous : previous - exponent; } } } if (difference == 0) { int result = ask(cycleVertex, MAX_VERTEX); if (result == cycleVertex) { difference = MAX_VERTEX; } else { constexpr int64 FALLBACK_MULTIPLE = 223092870; result = ask(cycleVertex, FALLBACK_MULTIPLE); if (result == cycleVertex) { difference = FALLBACK_MULTIPLE; } } } int64 answer = (difference != 0) ? recoverPeriod(difference, cycleVertex) : MAX_VERTEX; cout << "! " << answer << endl; int verdict; if (!(cin >> verdict) || verdict != 1) return 0; } return 0; }