题面
来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。
Problem: X-OR
Time limit: 1 second
Memory limit: 256 MB
This is an interactive problem!
Ehab has a hidden permutation p of length n consisting of the elements from 0 to n-1. You, for some reason, want to figure out the permutation.
To do that, you can give Ehab 2 different indices i and j, and he'll reply with (p_i | p_j) where | is the bitwise-or operation.
You can ask queries to figure out the permutation. However, making too many queries will reduce your score, and using n*n or more queries will result in 0 points. Ehab is too lazy to play your silly games, so he'll fix the permutation beforehand and will not change it depending on your queries.
Input
The only line contains the integer n (3 <= n <= 2048) -- the length of the permutation.
Interaction Protocol
To ask a question, print "? i j" (without quotes, i != j). Then, you should read the answer, which will be (p_i | p_j).
If we answer with -1 instead of a valid answer, that means you exceeded the number of queries or made an invalid query. Exit immediately after receiving -1 and you will see Wrong Answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
To print the answer, print "! p_1 p_2 ... p_n" (without quotes). Note that answering doesn't count as one of the queries.
After printing a query or printing the answer, do not forget to output end of line and flush the output.
Otherwise, you will get Idleness limit exceeded. To do this, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see documentation for other languages.
Scoring
The physical objective is per-graph query count Q_j; smaller is better. The physical reference is `a = R_j = floor(2*n_j+2*log2(n_j)); if R_j>=n_j*n_j then n_j*(n_j-1)/2`; matching a positive reference earns 60 points.
Define the historical low-score expression (in points):
P_low = 60*max(0,(n_j*n_j-Q_j)/(n_j*n_j-R_j))^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.
Example Input:
3
1
3
2
Example Output:
? 1 2
? 1 3
? 2 3
! 1 0 2
结果
Kimi K3.1 ProKimi
max
60.1
平均得分 ↑
- 60.1采样 1 · 部分分
- 36.9k平均输出 token(含思考) ↓
- 27.6输出速度 tokens/s ↑
- 1341 秒延迟 ↓
Kimi K3.1 Pro(high)Kimi high
high
60.1
平均得分 ↑
- 60.1采样 1 · 部分分
- 14.2k平均输出 token(含思考) ↓
- 25.2输出速度 tokens/s ↑
- 564 秒延迟 ↓
DeepSeek Flash V4.1-1017DeepSeek
auto(high)
53.8
平均得分 ↑
- 53.8采样 1 · 部分分
- 64.8k平均输出 token(含思考) ↓
- 192.0输出速度 tokens/s ↑
- 338 秒延迟 ↓
MiniMax M3.1 FlashMiniMax
auto(max)
60.2
平均得分 ↑
- 60.2采样 1 · 部分分
- 125.1k平均输出 token(含思考) ↓
- 207.9输出速度 tokens/s ↑
- 602 秒延迟 ↓
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
Kimi K3.1 Pro · 采样 1 · 94 行
#include <bits/stdc++.h> using namespace std; struct Query { int a, b, res; }; int n; map<pair<int, int>, int> cache; vector<Query> history; int ask(int a, int b) { if (a > b) swap(a, b); auto key = make_pair(a, b); auto it = cache.find(key); if (it != cache.end()) return it->second; cout << "? " << a + 1 << " " << b + 1 << endl; cout.flush(); int res; cin >> res; if (res == -1) exit(0); cache[key] = res; history.push_back({a, b, res}); return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; vector<int> candidates(n); iota(candidates.begin(), candidates.end(), 0); vector<int> answer(n, -1); int zero = -1; while (zero == -1) { if (candidates.size() == 1) { zero = candidates[0]; break; } int a = candidates[0]; int value = ~0; vector<pair<int, int>> results; for (int i = 1; i < (int)candidates.size(); ++i) { int b = candidates[i]; int res = ask(a, b); value &= res; results.push_back({b, res}); } answer[a] = value; if (value == 0) { zero = a; break; } vector<int> nextCandidates; for (auto [b, res] : results) { if (res == value) nextCandidates.push_back(b); } candidates.swap(nextCandidates); } answer[zero] = 0; for (const auto &q : history) { if (q.a == zero) answer[q.b] = q.res; if (q.b == zero) answer[q.a] = q.res; } for (int i = 0; i < n; ++i) { if (answer[i] == -1) { answer[i] = ask(zero, i); } } cout << "!"; for (int i = 0; i < n; ++i) { cout << " " << answer[i]; } cout << endl; cout.flush(); return 0; }
Kimi K3.1 Pro(high) · 采样 1 · 80 行
#include <bits/stdc++.h> using namespace std; int n; int ask(int a, int b) { cout << "? " << a + 1 << ' ' << b + 1 << endl; int response; cin >> response; if (response == -1) exit(0); return response; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count()); vector<int> candidates(n), known(n, -1), answer(n, -1); iota(candidates.begin(), candidates.end(), 0); int zero = -1; while (zero == -1 && candidates.size() > 1) { shuffle(candidates.begin(), candidates.end(), rng); int anchor = candidates[0]; vector<int> result(n, -1); int value = (1 << 12) - 1; for (int i : candidates) { if (i == anchor) continue; result[i] = ask(anchor, i); value &= result[i]; } known[anchor] = value; if (value == 0) { zero = anchor; answer[zero] = 0; for (int i : candidates) { if (i != zero) answer[i] = result[i]; } break; } vector<int> nextCandidates; for (int i : candidates) { if (i != anchor && result[i] == value) { nextCandidates.push_back(i); } } candidates.swap(nextCandidates); } if (zero == -1) { zero = candidates[0]; answer[zero] = 0; known[zero] = 0; } for (int i = 0; i < n; ++i) { if (answer[i] != -1) continue; if (known[i] != -1) { answer[i] = known[i]; } else { answer[i] = ask(zero, i); } } cout << "!"; for (int x : answer) cout << ' ' << x; cout << endl; return 0; }
DeepSeek Flash V4.1-1017 · 采样 1 · 56 行
#include <bits/stdc++.h> using namespace std; int query(int i, int j) { cout << "? " << i + 1 << " " << j + 1 << endl; int x; cin >> x; if (x == -1) exit(0); return x; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> ans(n); int c = 0; vector<int> ors; while (true) { int res = -1; ors.assign(n, -1); for (int i = 0; i < n; i++) { if (i == c) continue; int x = query(c, i); ors[i] = x; if (res == -1) res = x; else res &= x; } ors[c] = res; int val = res; if (val == 0) { ans[c] = 0; for (int i = 0; i < n; i++) { if (i == c) ans[i] = 0; else ans[i] = query(c, i); } cout << "!"; for (int i = 0; i < n; i++) cout << " " << ans[i]; cout << endl; return 0; } int new_c = -1; for (int i = 0; i < n; i++) { if (i != c && ors[i] == val) { new_c = i; break; } } if (new_c == -1) { new_c = (c + 1) % n; } c = new_c; } return 0; }
MiniMax M3.1 Flash · 采样 1 · 118 行
#include <bits/stdc++.h> using namespace std; static int n; static vector<int> perm; static mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count()); static int ask(int i, int j) { cout << "? " << (i + 1) << ' ' << (j + 1) << endl; int r; if (!(cin >> r)) exit(0); if (r == -1) exit(0); return r; } /* Invariant: the leaves in G hold exactly the values { u : u is a submask of W } \ {W} (so |G| = 2^popcount(W) - 1 and 0 belongs to the set). Returns the leaf whose hidden value equals 0. */ static int findZero(const vector<int>& G) { if (G.size() == 1) return G[0]; const int m = (int)G.size(); const int x = G[(int)(rng() % m)]; vector<int> av(m, -1); int w = -1; for (int i = 0; i < m; i++) { if (G[i] == x) continue; av[i] = ask(x, G[i]); w = (w < 0) ? av[i] : (w & av[i]); } /* w == p_x (AND trick: every bit is missing from at least two values) */ if (w == 0) { for (int i = 0; i < m; i++) if (G[i] != x) perm[G[i]] = av[i]; return x; } vector<int> G2; for (int i = 0; i < m; i++) { if (G[i] == x) continue; if ((av[i] & ~w) == 0) G2.push_back(G[i]); } return findZero(G2); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); if (!(cin >> n)) return 0; perm.assign(n, -1); if (n <= 4) { /* tiny instances: ask everything and solve by backtracking */ vector<vector<int>> q(n, vector<int>(n, -1)); for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) { q[i][j] = q[j][i] = ask(i, j); } vector<int> p(n, -1); vector<char> used(n, 0); function<bool(int)> rec = [&](int i) -> bool { if (i == n) return true; for (int v = 0; v < n; v++) { if (used[v]) continue; bool ok = true; for (int j = 0; j < i; j++) if ((v | p[j]) != q[i][j]) { ok = false; break; } if (!ok) continue; p[i] = v; used[v] = 1; if (rec(i + 1)) return true; used[v] = 0; } return false; }; rec(0); cout << "!"; for (int i = 0; i < n; i++) cout << ' ' << p[i]; cout << endl; return 0; } /* step 1: a star around vertex 0 -> p_0 and p_j & ~p_0 for every other j */ vector<int> a(n, -1); int c = -1; for (int j = 1; j < n; j++) { a[j] = ask(0, j); c = (c < 0) ? a[j] : (c & a[j]); } perm[0] = c; int z; if (c == 0) { /* p_0 == 0 : the star already revealed every value */ z = 0; for (int j = 1; j < n; j++) perm[j] = a[j]; } else { /* leaves whose value is a submask of c contain the value 0 */ vector<int> G0; for (int j = 1; j < n; j++) if ((a[j] & ~c) == 0) G0.push_back(j); z = findZero(G0); } perm[z] = 0; /* step 2: read every remaining value using the zero vertex */ for (int j = 0; j < n; j++) { if (j == 0 || j == z || perm[j] != -1) continue; perm[j] = ask(z, j); } cout << "!"; for (int i = 0; i < n; i++) cout << ' ' << perm[i]; cout << endl; return 0; }