题面
来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。
Pen
This is an I/O interactive problem. I/O interaction refers to interactive problems, where the program communicates with a special judge during execution instead of producing all output at once. In these problems, the program sends queries (output) to the judge and must immediately read responses (input) before continuing. The solution must strictly follow the input-output protocol defined in the problem statement, because any extra output, missing flush, or incorrect format can cause a wrong answer. Unlike standard problems, interactive problems require careful handling of I/O, synchronization, and flushing to ensure smooth communication between the contestant’s code and the judge.
There are n pens, numbered from 0 to n − 1.
Each pen contains a certain amount of ink — let the i-th pen have p_i units of ink.
You only know that (p_0, p_1, …, p_{n-1}) is a permutation of 0 … n − 1, but you do not know the exact values of p_i.
Your task is to choose two pens such that together they have at least n units of ink remaining.
You cannot directly query the amount of ink in any pen.
Instead, you can only “try to write” with a pen — then you will learn whether it can still write or not.
If it can write, it will consume 1 unit of ink.
Note that the requirement refers to the remaining ink in the two chosen pens:
when you finally select them, their total remaining ink must be at least n.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1001). The description of the test cases follows.
Each test case contains one integer n (10 ≤ n ≤ 25), the number of pens.
Interaction
To use a pen, output one line. First output 0 followed by a space, then output the number of the pen you want to use. After flushing your output, your program should read a single integer x, x = 0 means that the pen was already empty, x = 1 means the pen still had ink before consuming 1 unit of ink (can be empty now).
If you want to select two pens, output one line. First output 1 followed by a space. Then output the number of those two pens, separated by a space. Note that they cannot be the same pen. After flushing your output, you should start processing the next test case (or end the code if there is no next test case).
## Scoring
Let x be c, the number of correct answers. t is the total number of answers requested. Zero correct answers do not earn 100. The physical reference (the 60-point level) is a=0.6*t. Define the lower-band continuation:
L(x) = 100*c/t.
For positive x and positive physical reference a, define the improvement factor r=x/a. The physical reference has r=1 and earns 60 points. For a valid output on this branch, the points P are:
P = L(x), if L(x)<=60;
P = min(100,60+ln(r)), otherwise.
Here ln is the natural logarithm. In the upper branch before the 100-point cap, r=exp(P-60): each additional point requires an e-fold improvement in the physical objective (multiplication by e). A zero maximization objective is not a full-score exception. All feasibility, correctness, and hard resource-limit checks remain required; invalid output receives 0.
Across test files, use the arithmetic mean of the file scores.
结果
Kimi K3.1 ProKimi
max
60.1
平均得分 ↑
- 60.1采样 1 · 部分分
- 51.9k平均输出 token(含思考) ↓
- 24.4输出速度 tokens/s ↑
- 2128 秒延迟 ↓
Kimi K3.1 Pro(high)Kimi high
high
0.0
平均得分 ↑
- 0.0采样 1 · 部分分
- 15.7k平均输出 token(含思考) ↓
- 15.6输出速度 tokens/s ↑
- 1011 秒延迟 ↓
DeepSeek Flash V4.1-1017DeepSeek
auto(high)
46.8
平均得分 ↑
- 46.8采样 1 · 部分分
- 69.5k平均输出 token(含思考) ↓
- 183.3输出速度 tokens/s ↑
- 379 秒延迟 ↓
MiniMax M3.1 FlashMiniMax
auto(max)
54.4
平均得分 ↑
- 54.4采样 1 · 部分分
- 70.4k平均输出 token(含思考) ↓
- 93.5输出速度 tokens/s ↑
- 755 秒延迟 ↓
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
Kimi K3.1 Pro · 采样 1 · 190 行
#include <bits/stdc++.h> using namespace std; struct Node { double value; int action; // 0: answer, 1: race, 2: drain one pen }; struct TestSolver { int n; unordered_map<uint32_t, Node> memo; explicit TestSolver(int n_) : n(n_) { memo.reserve(4096); } pair<double, double> immediate(uint32_t mask) { vector<int> v; for (int i = 0; i < n; ++i) { if (mask & (1u << i)) v.push_back(i); } int m = (int)v.size(); int goodPairs = 0; for (int i = 0; i < m; ++i) { for (int j = i + 1; j < m; ++j) { goodPairs += (v[i] + v[j] >= n); } } double q = 0.0; if (m >= 2) { q = (double)goodPairs / ((double)m * (m - 1) / 2.0); } double r = 0.0; if (m >= 3) { int a = v[m - 3]; int b = v[m - 2]; int c = v[m - 1]; int d = b + c - 2 * a - n; int goodOrders = max(0, min(3, d + 1)); r = (double)goodOrders / 3.0; } return {q, r}; } Node dp(uint32_t mask) { auto it = memo.find(mask); if (it != memo.end()) return it->second; int m = __builtin_popcount(mask); auto [q, r] = immediate(mask); if (m <= 2) { Node res{q, 0}; memo[mask] = res; return res; } Node res{q, 0}; if (r > res.value + 1e-12) res = {r, 1}; if (res.value >= 1.0 - 1e-12) { memo[mask] = res; return res; } double continuation = 0.0; for (int i = 0; i < n; ++i) { if (mask & (1u << i)) { continuation += dp(mask ^ (1u << i)).value; } } continuation /= m; if (continuation > res.value + 1e-12) { res = {continuation, 2}; } memo[mask] = res; return res; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; if (!(cin >> t)) return 0; mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count()); auto usePen = [&](int id) { cout << "0 " << id << endl; int x; if (!(cin >> x)) exit(0); return x; }; auto answer = [&](int a, int b) { cout << "1 " << a << " " << b << endl; }; while (t--) { int n; if (!(cin >> n)) return 0; vector<int> pens(n); iota(pens.begin(), pens.end(), 0); shuffle(pens.begin(), pens.end(), rng); uint32_t mask = (n == 32 ? ~0u : ((1u << n) - 1)); TestSolver solver(n); auto race = [&](const vector<int>& group) { vector<int> active = group; vector<char> alive(n, 0); for (int id : active) alive[id] = 1; int remaining = (int)active.size(); while (remaining > 2) { vector<int> round = active; for (int id : round) { if (remaining == 2) break; if (!alive[id]) continue; int x = usePen(id); if (x == 0) { alive[id] = 0; --remaining; } } active.clear(); for (int id : round) { if (alive[id]) active.push_back(id); } } answer(active[0], active[1]); }; while (true) { int m = (int)pens.size(); if (m == 2) { answer(pens[0], pens[1]); break; } auto [q, r] = solver.immediate(mask); int action; if (m <= 10) { action = solver.dp(mask).action; } else { double best = max(q, r); if (best >= 2.0 / 3.0 - 1e-12) { action = (r > q + 1e-12 ? 1 : 0); } else { action = 2; } } if (action == 0) { answer(pens[0], pens[1]); break; } if (action == 1) { race(pens); break; } int id = pens[0]; int p = 0; while (usePen(id) == 1) ++p; pens.erase(pens.begin()); mask &= ~(1u << p); } } return 0; }
Kimi K3.1 Pro(high) · 采样 1 · 196 行
#include <bits/stdc++.h> using namespace std; mt19937 rng(random_device{}()); int askPen(int id) { cout << 0 << ' ' << id << endl; int response; cin >> response; return response; } void answerPair(int a, int b) { cout << 1 << ' ' << a << ' ' << b << endl; } int emptyPen(int id) { int value = 0; while (true) { int response = askPen(id); if (response == 0) return value; ++value; } } double randomPairSuccess(const vector<int>& values, int n) { int k = (int)values.size(); int good = 0; for (int i = 0; i < k; ++i) { for (int j = i + 1; j < k; ++j) { if (values[i] + values[j] >= n) ++good; } } return (double)good / ((double)k * (k - 1) / 2.0); } double threePenValue(vector<int> values, int n) { sort(values.begin(), values.end()); int a = values[0], b = values[1], c = values[2]; if (a + b >= n) return 1.0; if (b + c < n) return 0.0; int damage = a + 1; int slack = b + c - n; double result = 1.0; if (slack >= damage) result += 1.0; if (slack >= 2 * damage) result += 1.0; return result / 3.0; } struct StateSolver { int n; map<vector<int>, double> memo; double solve(vector<int> values) { sort(values.begin(), values.end()); auto it = memo.find(values); if (it != memo.end()) return it->second; int k = (int)values.size(); double result; if (k == 3) { result = threePenValue(values, n); } else { double stop = randomPairSuccess(values, n); double eliminate = 0.0; for (int i = 0; i < k; ++i) { vector<int> next = values; next.erase(next.begin() + i); eliminate += solve(next); } eliminate /= k; result = max(stop, eliminate); } memo[values] = result; return result; } bool shouldEliminate(vector<int> values) { sort(values.begin(), values.end()); double stop = randomPairSuccess(values, n); double eliminate = 0.0; int k = (int)values.size(); for (int i = 0; i < k; ++i) { vector<int> next = values; next.erase(next.begin() + i); eliminate += solve(next); } eliminate /= k; return eliminate > stop + 1e-12; } }; void outputRandomPair(vector<int> pens) { shuffle(pens.begin(), pens.end(), rng); answerPair(pens[0], pens[1]); } void solveThreePens(vector<int> pens, vector<int> values, int n) { sort(values.begin(), values.end()); int a = values[0], b = values[1], c = values[2]; if (a + b >= n || b + c < n) { outputRandomPair(pens); return; } shuffle(pens.begin(), pens.end(), rng); int x = pens[0], y = pens[1], z = pens[2]; int damage = a + 1; bool xIsHigh = true; for (int i = 0; i < damage; ++i) { if (askPen(x) == 0) { xIsHigh = false; break; } } if (!xIsHigh) { answerPair(y, z); return; } bool yIsHigh = true; for (int i = 0; i < damage; ++i) { if (askPen(y) == 0) { yIsHigh = false; break; } } if (!yIsHigh) answerPair(x, z); else answerPair(x, y); } void runTestCase(int n) { const int adaptiveLimit = 12; vector<int> pens(n), values(n); iota(pens.begin(), pens.end(), 0); iota(values.begin(), values.end(), 0); shuffle(pens.begin(), pens.end(), rng); while ((int)pens.size() > adaptiveLimit) { if (randomPairSuccess(values, n) >= 1.0) { outputRandomPair(pens); return; } int pos = uniform_int_distribution<int>(0, (int)pens.size() - 1)(rng); int id = pens[pos]; int value = emptyPen(id); pens.erase(pens.begin() + pos); values.erase(find(values.begin(), values.end(), value)); } StateSolver solver; solver.n = n; solver.solve(values); while ((int)pens.size() > 3) { if (!solver.shouldEliminate(values)) { outputRandomPair(pens); return; } int pos = uniform_int_distribution<int>(0, (int)pens.size() - 1)(rng); int id = pens[pos]; int value = emptyPen(id); pens.erase(pens.begin() + pos); values.erase(find(values.begin(), values.end(), value)); } solveThreePens(pens, values, n); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; runTestCase(n); } return 0; }
DeepSeek Flash V4.1-1017 · 采样 1 · 128 行
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; const int K = 10; vector<bool> used(n, false); // Empty pens 0 to n-K-1 for (int i = 0; i < n - K; i++) { int v = 0; while (true) { cout << "0 " << i << endl; cout.flush(); int x; cin >> x; if (x == 0) break; v++; } used[v] = true; } // Collect remaining values S vector<int> S; for (int v = 0; v < n; v++) { if (!used[v]) S.push_back(v); } // DP int totalMasks = 1 << K; vector<double> dp(totalMasks, 0.0); for (int mask = 0; mask < totalMasks; mask++) { int k = __builtin_popcount(mask); if (k < 2) { dp[mask] = 0.0; continue; } vector<int> rem; for (int i = 0; i < K; i++) { if (mask & (1 << i)) { rem.push_back(S[i]); } } int valid = 0; for (int a = 0; a < k; a++) { for (int b = a + 1; b < k; b++) { if (rem[a] + rem[b] >= n) { valid++; } } } double stopProb = (double)valid / (k * (k - 1) / 2); double emptyProb = 0.0; for (int i = 0; i < K; i++) { if (mask & (1 << i)) { emptyProb += dp[mask ^ (1 << i)]; } } emptyProb /= k; dp[mask] = max(stopProb, emptyProb); } // Execute strategy int mask = totalMasks - 1; vector<int> remaining_pens; for (int i = 0; i < K; i++) { remaining_pens.push_back(n - K + i); } while (true) { int k = __builtin_popcount(mask); if (k < 2) { break; } vector<int> rem; for (int i = 0; i < K; i++) { if (mask & (1 << i)) { rem.push_back(S[i]); } } int valid = 0; for (int a = 0; a < k; a++) { for (int b = a + 1; b < k; b++) { if (rem[a] + rem[b] >= n) { valid++; } } } double stopProb = (double)valid / (k * (k - 1) / 2); double emptyProb = 0.0; for (int i = 0; i < K; i++) { if (mask & (1 << i)) { emptyProb += dp[mask ^ (1 << i)]; } } emptyProb /= k; if (stopProb >= emptyProb) { int pen1 = remaining_pens[0]; int pen2 = remaining_pens[1]; cout << "1 " << pen1 << " " << pen2 << endl; cout.flush(); break; } else { int pen = remaining_pens[0]; int v = 0; while (true) { cout << "0 " << pen << endl; cout.flush(); int x; cin >> x; if (x == 0) break; v++; } int idx = -1; for (int i = 0; i < K; i++) { if ((mask & (1 << i)) && S[i] == v) { idx = i; break; } } mask ^= (1 << idx); remaining_pens.erase(remaining_pens.begin()); } } } return 0; }
MiniMax M3.1 Flash · 采样 1 · 218 行
#include <bits/stdc++.h> using namespace std; using int64 = long long; using uint64 = unsigned long long; struct Entity { int limit; int consumed; int pen; }; struct PairInfo { uint64 favorable = 0; uint64 expectedNumerator = 0; int minimumSum = INT_MAX; }; static pair<int, int> chooseBestPair( int n, const vector<Entity>& entities, const vector<int>& capacities ) { const int m = (int)entities.size(); vector<int> order(m); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&](int a, int b) { return entities[a].limit > entities[b].limit; }); vector<int> greaterCount(m, 0); for (int i = 0; i < m; ++i) { for (int c : capacities) { if (c > entities[i].limit) { ++greaterCount[i]; } } } uint64 totalAssignments = 1; for (int k = 0; k < m; ++k) { int e = order[k]; int choices = greaterCount[e] - k; if (choices <= 0) { totalAssignments = 0; break; } totalAssignments *= choices; } auto completionWays = [&](int a, int b, int x, int y) -> uint64 { uint64 ways = 1; int used = 0; for (int e : order) { if (e == a || e == b) continue; int allowed = greaterCount[e]; allowed -= (x > entities[e].limit); allowed -= (y > entities[e].limit); int choices = allowed - used; if (choices <= 0) return 0; ways *= choices; ++used; } return ways; }; vector<vector<PairInfo>> info(m, vector<PairInfo>(m)); for (int a = 0; a < m; ++a) { for (int b = a + 1; b < m; ++b) { PairInfo& result = info[a][b]; for (int x : capacities) { if (x <= entities[a].limit) continue; for (int y : capacities) { if (y == x || y <= entities[b].limit) continue; uint64 ways = completionWays(a, b, x, y); if (ways == 0) continue; int remainingSum = x - entities[a].consumed + y - entities[b].consumed; result.minimumSum = min(result.minimumSum, remainingSum); result.expectedNumerator += ways * static_cast<uint64>(remainingSum); if (remainingSum >= n) { result.favorable += ways; } } } } } int bestA = -1; int bestB = -1; tuple<int, uint64, int, uint64> bestKey{-1, 0, -1, 0}; for (int a = 0; a < m; ++a) { for (int b = a + 1; b < m; ++b) { const PairInfo& current = info[a][b]; int guaranteed = (current.minimumSum >= n); auto key = make_tuple( guaranteed, current.favorable, current.minimumSum, current.expectedNumerator ); if (bestA == -1 || key > bestKey) { bestKey = key; bestA = a; bestB = b; } } } if (bestA == -1) { return {0, 1}; } return {entities[bestA].pen, entities[bestB].pen}; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); mt19937_64 rng( chrono::steady_clock::now().time_since_epoch().count() ^ static_cast<uint64>(random_device{}()) ); auto ask = [&](int pen) -> bool { cout << 0 << ' ' << pen << endl; int response; if (!(cin >> response)) { exit(0); } return response == 1; }; int t; if (!(cin >> t)) return 0; while (t--) { int n; if (!(cin >> n)) return 0; vector<int> pens(n); iota(pens.begin(), pens.end(), 0); shuffle(pens.begin(), pens.end(), rng); int reservedCount = (n % 2 == 0 ? 2 : 1); int pairCount = (n - reservedCount) / 2; vector<Entity> entities; vector<int> lowerCapacities; for (int i = 0; i < reservedCount; ++i) { entities.push_back({-1, 0, pens[i]}); } for (int i = 0; i < pairCount; ++i) { int a = pens[reservedCount + 2 * i]; int b = pens[reservedCount + 2 * i + 1]; if (rng() & 1ULL) swap(a, b); int consumedA = 0; int consumedB = 0; while (true) { if (!ask(a)) { lowerCapacities.push_back(consumedA); entities.push_back({consumedA, consumedB, b}); break; } ++consumedA; if (!ask(b)) { lowerCapacities.push_back(consumedB); entities.push_back({consumedB, consumedA, a}); break; } ++consumedB; } } vector<bool> excluded(n, false); for (int capacity : lowerCapacities) { excluded[capacity] = true; } vector<int> capacities; for (int capacity = 0; capacity < n; ++capacity) { if (!excluded[capacity]) { capacities.push_back(capacity); } } auto [first, second] = chooseBestPair(n, entities, capacities); cout << 1 << ' ' << first << ' ' << second << endl; } return 0; }