题面
来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。
Problem: Distinct Pairwise XOR Set
Time Limit: 1 second
Memory Limit: 512 MB
Description
Given an integer n, find a subset S ⊆ {1, 2, ..., n} such that:
1) For all pairs (a, b) with a, b ∈ S and a < b, the values (a XOR b) are all distinct (i.e., no two different unordered pairs produce the same XOR).
2) |S| ≥ floor(sqrt(n / 2)).
Input
A single integer n (1 ≤ n ≤ 10^7).
Output
- First line: an integer m — the size of the set S.
- Second line: m distinct integers in the range [1, n] — the elements of S, in any order.
Notes
- Any valid S is accepted. You do NOT need to maximize m; you only need m ≥ floor(sqrt(n/2)).
- The pairwise XOR distinctness means the set {a_i XOR a_j | 1 ≤ i < j ≤ m} has size m*(m-1)/2.
- Multiple correct outputs may exist for the same n.
- Print out the sequence with the longest length.
Sample
Input
49
Output
4
1 2 3 4
## Scoring
All feasibility and interaction limits apply before scoring; invalid output receives zero. Points are averaged over test files. For the logarithmic branch, write x for the original maximizing quantity or quality and a for its physical 60-point reference. The improvement factor is r=x/a, and the upper-band award is P=min(100,60+ln(r)). Here ln is natural: r=1 corresponds to 60 points, and on the uncapped logarithmic upper band, r=exp(P-60). Each additional point multiplies the physical improvement factor by e (divides a minimizing objective by e or multiplies a maximizing objective by e, as applicable). The lower-band, zero-objective, and completion rules below still apply.
X is the submitted valid XOR-set size and R>0 is the size of the validated reference set. Define the objective x=X, its physical reference a=A=R, and the lower-band calculation L=60*X/R.
```text
P = L, if L <= 60
P = min(100, 60 + ln(r)), otherwise
```
Zero value of a maximizing objective is not a perfect solution and earns no special full-score award. The checker reports P/100.
结果
Kimi K3.1 ProKimi
max
60.0
平均得分 ↑
- 60.0采样 1 · 部分分
- 36.0k平均输出 token(含思考) ↓
- 28.9输出速度 tokens/s ↑
- 1246 秒延迟 ↓
Kimi K3.1 Pro(high)Kimi high
high
60.0
平均得分 ↑
- 60.0采样 1 · 部分分
- 13.3k平均输出 token(含思考) ↓
- 26.5输出速度 tokens/s ↑
- 507 秒延迟 ↓
DeepSeek Flash V4.1-1017DeepSeek
auto(high)
60.0
平均得分 ↑
- 60.0采样 1 · 部分分
- 71.3k平均输出 token(含思考) ↓
- 174.7输出速度 tokens/s ↑
- 408 秒延迟 ↓
MiniMax M3.1 FlashMiniMax
auto(max)
60.0
平均得分 ↑
- 60.0采样 1 · 部分分
- 89.4k平均输出 token(含思考) ↓
- 80.0输出速度 tokens/s ↑
- 1118 秒延迟 ↓
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
Kimi K3.1 Pro · 采样 1 · 97 行
#include <bits/stdc++.h> using namespace std; static inline int gf_mul(int a, int b, int k, int poly) { int res = 0; const int top = 1 << k; while (b) { if (b & 1) res ^= a; b >>= 1; a <<= 1; if (a & top) a ^= poly; } return res & (top - 1); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; const int poly[13] = { 0, 0x3, 0x7, 0xB, 0x13, 0x25, 0x43, 0x83, 0x11D, 0x211, 0x409, 0x805, 0x1053 }; int bestCount = 1; int bestK = -1, bestType = 0, bestC = 0; for (int k = 1; k <= 12; ++k) { const int q = 1 << k; vector<int> cube(q); for (int x = 0; x < q; ++x) { int sq = gf_mul(x, x, k, poly[k]); cube[x] = gf_mul(sq, x, k, poly[k]); } for (int c = 0; c < q; ++c) { int cnt0 = 0, cnt1 = 0; for (int x = 0; x < q; ++x) { int f = cube[x] ^ c; int v0 = (x << k) | f; int v1 = (f << k) | x; if (v0 >= 1 && v0 <= n) ++cnt0; if (v1 >= 1 && v1 <= n) ++cnt1; } if (cnt0 > bestCount) { bestCount = cnt0; bestK = k; bestType = 0; bestC = c; } if (cnt1 > bestCount) { bestCount = cnt1; bestK = k; bestType = 1; bestC = c; } } } vector<int> answer; if (bestK == -1) { answer.push_back(1); } else { const int k = bestK; const int q = 1 << k; vector<int> cube(q); for (int x = 0; x < q; ++x) { int sq = gf_mul(x, x, k, poly[k]); cube[x] = gf_mul(sq, x, k, poly[k]); } for (int x = 0; x < q; ++x) { int f = cube[x] ^ bestC; int v = (bestType == 0) ? ((x << k) | f) : ((f << k) | x); if (v >= 1 && v <= n) answer.push_back(v); } } cout << answer.size() << '\n'; for (size_t i = 0; i < answer.size(); ++i) { if (i) cout << ' '; cout << answer[i]; } cout << '\n'; return 0; }
Kimi K3.1 Pro(high) · 采样 1 · 54 行
#include <bits/stdc++.h> using namespace std; int gfMul(int a, int b, int k, int poly) { int res = 0; int mask = (1 << k) - 1; for (int i = 0; i < k; ++i) { if (b & 1) res ^= a; b >>= 1; bool carry = (a >> (k - 1)) & 1; a = (a << 1) & mask; if (carry) a ^= (poly & mask); } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; const int polys[13] = { 0, 0x3, 0x7, 0xB, 0x13, 0x25, 0x43, 0x83, 0x11B, 0x211, 0x409, 0x805, 0x1053 }; vector<int> best; for (int k = 1; k <= 12; ++k) { int q = 1 << k; vector<int> cur; for (int x = 0; x < q; ++x) { int x2 = gfMul(x, x, k, polys[k]); int x3 = gfMul(x2, x, k, polys[k]); int low = x3 ^ 1; int value = (x << k) | low; if (value <= n) cur.push_back(value); } if (cur.size() > best.size()) best.swap(cur); } cout << best.size() << '\n'; for (size_t i = 0; i < best.size(); ++i) { if (i) cout << ' '; cout << best[i]; } cout << '\n'; return 0; }
DeepSeek Flash V4.1-1017 · 采样 1 · 169 行
#include <bits/stdc++.h> using namespace std; int polyMod(int a, int b) { if (a == 0) return 0; int db = 31 - __builtin_clz(b); while (a) { int da = 31 - __builtin_clz(a); if (da < db) break; a ^= (b << (da - db)); } return a; } int findIrreducible(int k) { if (k == 0) return 1; int start = (1 << k) | 1; int end = (1 << (k + 1)); for (int mod = start; mod < end; mod += 2) { bool ok = true; for (int d = 1; d <= k / 2; ++d) { int maxLow = 1 << d; for (int low = 0; low < maxLow; ++low) { int divisor = (1 << d) | low; if (polyMod(mod, divisor) == 0) { ok = false; break; } } if (!ok) break; } if (ok) return mod; } return 0; } int gf_mul(int a, int b, int mod, int k) { int res = 0; int high = 1 << k; while (b) { if (b & 1) res ^= a; b >>= 1; a <<= 1; if (a & high) a ^= mod; } return res & (high - 1); } int findBestShift(const vector<int>& S, int n, int N, int& bestC) { vector<int> diff(N + 1, 0); struct Interval { int Y, len, r; }; vector<Interval> intervals; int L = 1, R = n; while (L <= R) { int len = 1; while (((L % (len * 2)) == 0) && (L + len * 2 - 1 <= R)) { len *= 2; } int r = __builtin_ctz(len); intervals.push_back({L, len, r}); L += len; } for (int s : S) { for (auto& iv : intervals) { int start = (((iv.Y >> iv.r) ^ (s >> iv.r)) << iv.r); diff[start] += 1; diff[start + iv.len] -= 1; } } int cur = 0, best = -1; bestC = 0; for (int c = 0; c < N; ++c) { cur += diff[c]; if (cur > best) { best = cur; bestC = c; } } return best; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; if (n == 1) { cout << "1\n1\n"; return 0; } int mods[25] = {}; for (int k = 1; k <= 12; ++k) { mods[k] = findIrreducible(k); } int N0 = 1, m0 = 0; while (N0 <= n) { N0 <<= 1; ++m0; } int maxM = min(24, m0 + 6); int bestCount = -1, bestM = -1, bestC = 0; for (int m = m0; m <= maxM; ++m) { int N = 1 << m; int k = m / 2; if (k == 0) continue; int q = 1 << k; int mod = mods[k]; vector<int> f(q); for (int x = 0; x < q; ++x) { int x2 = gf_mul(x, x, mod, k); f[x] = gf_mul(x2, x, mod, k); } vector<int> S(q); for (int x = 0; x < q; ++x) { S[x] = (x << k) | f[x]; } int c; int cnt = findBestShift(S, n, N, c); if (cnt > bestCount) { bestCount = cnt; bestM = m; bestC = c; } } int m = bestM; int N = 1 << m; int k = m / 2; int q = 1 << k; int mod = mods[k]; vector<int> f(q); for (int x = 0; x < q; ++x) { int x2 = gf_mul(x, x, mod, k); f[x] = gf_mul(x2, x, mod, k); } vector<int> ans; for (int x = 0; x < q; ++x) { int s = (x << k) | f[x]; int val = s ^ bestC; if (val >= 1 && val <= n) { ans.push_back(val); } } cout << ans.size() << '\n'; for (size_t i = 0; i < ans.size(); ++i) { if (i) cout << ' '; cout << ans[i]; } cout << '\n'; return 0; }
MiniMax M3.1 Flash · 采样 1 · 323 行
#include <bits/stdc++.h> using namespace std; using u32 = uint32_t; using i64 = long long; static u32 mulMod(u32 a, u32 b, u32 polynomial, int degree) { u32 result = 0; while (b) { if (b & 1U) result ^= a; b >>= 1; a <<= 1; if (a & (1U << degree)) a ^= polynomial; } return result; } static u32 powMod(u32 a, u32 exponent, u32 polynomial, int degree) { u32 result = 1; while (exponent) { if (exponent & 1U) result = mulMod(result, a, polynomial, degree); a = mulMod(a, a, polynomial, degree); exponent >>= 1; } return result; } static u32 findPrimitivePolynomial(int degree) { static vector<u32> cache(13, 0); if (cache[degree]) return cache[degree]; const int fieldSize = 1 << degree; int value = fieldSize - 1; vector<int> primeDivisors; for (int p = 2; p * p <= value; ++p) { if (value % p == 0) { primeDivisors.push_back(p); while (value % p == 0) value /= p; } } if (value > 1) primeDivisors.push_back(value); const u32 generator = (degree == 1 ? 1U : 2U); for (int low = 1; low < fieldSize; low += 2) { u32 polynomial = (1U << degree) | static_cast<u32>(low); if (powMod(generator, fieldSize - 1, polynomial, degree) != 1) continue; bool primitive = true; for (int p : primeDivisors) { if (powMod(generator, (fieldSize - 1) / p, polynomial, degree) == 1) { primitive = false; break; } } if (primitive) { cache[degree] = polynomial; return polynomial; } } return 0; } static void fwht(vector<i64>& a) { const int n = static_cast<int>(a.size()); for (int len = 1; len < n; len <<= 1) { for (int start = 0; start < n; start += 2 * len) { for (int j = 0; j < len; ++j) { const i64 x = a[start + j]; const i64 y = a[start + j + len]; a[start + j] = x + y; a[start + j + len] = x - y; } } } } struct Cap { int degree; int size; vector<u32> points; vector<u32> valid; }; static void makeRandomInvertibleMatrix(int bits, mt19937& rng, array<u32, 24>& columns) { const u32 mask = (1U << bits) - 1; array<u32, 24> pivot{}; for (int i = 0; i < bits; ++i) { while (true) { const u32 original = rng() & mask; u32 reduced = original; bool inserted = false; for (int bit = bits - 1; bit >= 0; --bit) { if (!(reduced & (1U << bit))) continue; if (pivot[bit]) { reduced ^= pivot[bit]; } else { pivot[bit] = reduced; columns[i] = original; inserted = true; break; } } if (inserted) break; } } } static void optimizeCap(const Cap& cap, int n, mt19937& rng, vector<u32>& globalBest) { const int degree = cap.degree; const int q = cap.size; if (static_cast<int>(globalBest.size()) >= q || static_cast<int>(cap.valid.size()) == q) { return; } constexpr int TRIALS = 12; constexpr int TOP_CANDIDATES = 384; const int nHigh = n / q; const int nLow = n % q; for (int trial = 0; trial < TRIALS; ++trial) { array<u32, 24> columns{}; makeRandomInvertibleMatrix(2 * degree, rng, columns); vector<u32> transformed(q); for (int i = 0; i < q; ++i) { u32 x = cap.points[i]; u32 y = 0; while (x) { const int bit = __builtin_ctz(x); y ^= columns[bit]; x &= x - 1; } transformed[i] = y; } vector<int> frequency(q, 0); for (u32 value : transformed) { ++frequency[value >> degree]; } vector<int> offset(q + 1, 0); for (int i = 0; i < q; ++i) { offset[i + 1] = offset[i] + frequency[i]; } vector<u32> cursor(offset.begin(), offset.end() - 1); vector<u32> lows(q); for (u32 value : transformed) { const int high = static_cast<int>(value >> degree); const u32 low = value & static_cast<u32>(q - 1); lows[cursor[high]++] = low; } vector<i64> a(q), b(q, 0); for (int i = 0; i < q; ++i) a[i] = frequency[i]; for (int i = 0; i < nHigh && i < q; ++i) b[i] = 1; fwht(a); fwht(b); for (int i = 0; i < q; ++i) a[i] *= b[i]; fwht(a); vector<int> base(q); for (int i = 0; i < q; ++i) base[i] = static_cast<int>(a[i] / q); vector<int> order(q); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&](int x, int y) { if (base[x] != base[y]) return base[x] > base[y]; return x < y; }); vector<unsigned char> forbidden(q, 0); int localBestCount = -1; u32 localBestTranslation = 0; const int limit = min(q, TOP_CANDIDATES); for (int index = 0; index < limit; ++index) { const int highTranslation = order[index]; const int boundaryHigh = nHigh ^ highTranslation; for (int p = offset[highTranslation]; p < offset[highTranslation + 1]; ++p) { forbidden[lows[p]] = 1; } int bestScore = -1000000000; int bestLowTranslation = 0; for (int lowTranslation = 0; lowTranslation < q; ++lowTranslation) { int boundaryCount = 0; for (int p = offset[boundaryHigh]; p < offset[boundaryHigh + 1]; ++p) { if (((lows[p] ^ static_cast<u32>(lowTranslation)) & static_cast<u32>(q - 1)) <= static_cast<u32>(nLow)) { ++boundaryCount; } } const int score = boundaryCount - static_cast<int>(forbidden[lowTranslation]); if (score > bestScore) { bestScore = score; bestLowTranslation = lowTranslation; } } const int total = base[highTranslation] + bestScore; if (total > localBestCount) { localBestCount = total; localBestTranslation = (static_cast<u32>(highTranslation) << degree) | static_cast<u32>(bestLowTranslation); } for (int p = offset[highTranslation]; p < offset[highTranslation + 1]; ++p) { forbidden[lows[p]] = 0; } } vector<u32> candidate; candidate.reserve(q); for (u32 value : transformed) { const u32 translated = value ^ localBestTranslation; if (translated != 0 && translated <= static_cast<u32>(n)) { candidate.push_back(translated); } } if (candidate.size() > globalBest.size()) { globalBest = move(candidate); } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; if (n == 1) { cout << "1\n1\n"; return 0; } int required = static_cast<int>(sqrt(static_cast<double>(n) / 2.0)); while (2LL * (required + 1) * (required + 1) <= n) ++required; while (2LL * required * required > n) --required; int initialDegree = 0; while ((1 << initialDegree) < required) ++initialDegree; initialDegree = max(initialDegree, 1); vector<Cap> caps; for (int degree = initialDegree; degree <= 12; ++degree) { const int q = 1 << degree; if (n / q + 2 < required) break; const u32 polynomial = findPrimitivePolynomial(degree); Cap cap{degree, q, {}, {}}; cap.points.reserve(q); for (int x = 0; x < q; ++x) { const u32 value = static_cast<u32>(x); const u32 square = mulMod(value, value, polynomial, degree); const u32 cube = mulMod(square, value, polynomial, degree); const u32 low = cube ^ 1U; const u32 point = (static_cast<u32>(x) << degree) | low; cap.points.push_back(point); if (point != 0 && point <= static_cast<u32>(n)) { cap.valid.push_back(point); } } caps.push_back(move(cap)); } vector<u32> best; for (const Cap& cap : caps) { if (cap.valid.size() > best.size()) { best = cap.valid; } } mt19937 rng(0x9E3779B9U ^ static_cast<u32>(n)); for (auto it = caps.rbegin(); it != caps.rend(); ++it) { optimizeCap(*it, n, rng, best); } sort(best.begin(), best.end()); cout << best.size() << '\n'; for (size_t i = 0; i < best.size(); ++i) { if (i) cout << ' '; cout << best[i]; } cout << '\n'; return 0; }