题目 › fcs-310

FrontierCS #310

FrontierCS 算法赛道 v1.1 · 2026-05 · L5 开放式 · C++17 · 时限 8 秒 · 0–100 连续分

查看原题跳到结果

题面

来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。

```markdown # Metallic Pink Resonator Layout ## Problem The Martians have built a circular relay with ports labeled `0,1,…,M-1`. Some ports will be equipped with **pink emitters**; the rest remain **plain reflectors**. If port `a` is an emitter and port `b` is a reflector, then together they can generate the frequency \[ (a+b)\bmod M. \] For each frequency `r`, the Martians know: - a **value** `w_r` gained for each successful generating pair producing `r`, - a **saturation limit** `d_r`: once `d_r` pairs producing `r` exist, extra pairs for `r` give no additional benefit. You must choose which ports become emitters, subject to a budget. Let `A` be the set of chosen emitters, and `B = {0,1,…,M-1} \ A` be the reflectors. For each residue `r`, define \[ c_r = |\{(a,b)\in A\times B : (a+b)\bmod M = r\}|, \] where pairs are **ordered**: choosing emitter `a` and reflector `b` is one pair. The contribution of residue `r` is \[ w_r \cdot \min(c_r, d_r). \] Your task is to output any feasible emitter set maximizing the total contribution. --- ## Input A single test file contains one instance. - The first line contains two integers `M` and `B` — the number of ports and the total budget. - The second line contains `M` integers `cost_0, cost_1, …, cost_{M-1}` — the cost of installing an emitter at each port. - The third line contains `M` integers `w_0, w_1, …, w_{M-1}` — the value of each residue. - The fourth line contains `M` integers `d_0, d_1, …, d_{M-1}` — the saturation limit of each residue. All residue arithmetic is modulo `M`. --- ## Output Output any feasible solution. - The first line must contain one integer `K` — the number of chosen emitter ports. - The second line must contain `K` distinct integers `p_1, p_2, …, p_K` in increasing order, each between `0` and `M-1`, denoting the emitter ports. A solution is **feasible** if: 1. all listed ports are distinct, 2. all listed ports are valid indices in `[0, M-1]`, 3. \(\sum_{i=1}^{K} cost_{p_i} \le B\). If your output is infeasible or malformed, your objective value is `0`. If `K = 0`, you may omit the second line. --- ## Objective For your chosen emitter set `A` and reflector set `B = [0, M-1] \ A`, compute for each residue `r`: \[ c_r = |\{(a,b)\in A\times B : (a+b)\bmod M = r\}|. \] Your objective value is \[ U = \sum_{r=0}^{M-1} w_r \cdot \min(c_r, d_r). \] Higher is better. --- ## Scoring For each official test instance, the judge also computes a deterministic **baseline** solution: 1. Sort all ports by `(cost_i, i)` ascending. 2. Traverse this order once. 3. Add port `i` to the emitter set iff doing so keeps the total cost at most `B`. The physical objective is selected-set utility U=compute_objective; larger is better. The physical reference is `a = U_base after affordable-singleton fallback`; matching a positive reference earns 60 points. Define the historical low-score expression (in points): P_low = 60*U/R. If `P_low<=60`, retain `max(0,P_low)`. For `P_low>60` and a positive physical reference and objective, award: r = U / a 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. R is the greedy baseline objective; if zero, use the cheapest affordable singleton (ties by port index), as in the checker. ## Constraints - `2 ≤ M ≤ 200000` - `1 ≤ cost_i ≤ 10^9` - `1 ≤ w_i ≤ 10^6` - `1 ≤ d_i ≤ M` - `1 ≤ B ≤ 10^18` - At least one port satisfies `cost_i ≤ B` The search space is exponential in `M`; exact optimization is not expected. - Time limit: 8 seconds - Memory limit: 1024 MB --- ## Example Input ```text 6 5 3 2 2 4 1 3 5 1 4 2 3 6 1 2 1 1 2 1 ``` Output ```text 3 1 2 4 ``` Brief explanation: - Chosen emitters: `{1,2,4}` - Total cost: `2 + 2 + 1 = 5`, so the solution is feasible. - Reflectors: `{0,3,5}` Ordered emitter-reflector pairs generate residues with counts: - residue `0`: 1 pair - residue `1`: 3 pairs - residue `2`: 1 pair - residue `3`: 1 pair - residue `4`: 2 pairs - residue `5`: 1 pair After applying saturation limits `d = [1,2,1,1,2,1]`, the objective is: \[ 5\cdot1 + 1\cdot2 + 4\cdot1 + 2\cdot1 + 3\cdot2 + 6\cdot1 = 25. \] For this instance, the baseline picks the same set, so r = U / R = 1 and the test score is 60 points.

结果

Kimi K3.1 ProKimi

max

61.1

平均得分 ↑

  • 61.1采样 1 · 部分分
  • 35.5k平均输出 token(含思考) ↓
  • 30.0输出速度 tokens/s ↑
  • 1184 秒延迟 ↓

Kimi K3.1 Pro(high)Kimi high

high

62.2

平均得分 ↑

  • 62.2采样 1 · 部分分
  • 22.1k平均输出 token(含思考) ↓
  • 27.1输出速度 tokens/s ↑
  • 817 秒延迟 ↓

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

62.2

平均得分 ↑

  • 62.2采样 1 · 部分分
  • 41.0k平均输出 token(含思考) ↓
  • 180.0输出速度 tokens/s ↑
  • 228 秒延迟 ↓

MiniMax M3.1 FlashMiniMax

auto(max)

26.1

平均得分 ↑

  • 26.1采样 1 · 部分分
  • 76.7k平均输出 token(含思考) ↓
  • 109.7输出速度 tokens/s ↑
  • 700 秒延迟 ↓

↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。

代码

Kimi K3.1 Pro · 采样 1 · 657 行
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using cd = complex<double>;

static constexpr double PI = 3.141592653589793238462643383279502884;

struct FFT {
    int n;
    vector<int> rev;
    vector<cd> roots;

    explicit FFT(int m) {
        n = 1;
        while (n < 2 * m) n <<= 1;
        rev.resize(n);
        for (int i = 1; i < n; ++i) {
            rev[i] = (rev[i >> 1] >> 1) | ((i & 1) ? (n >> 1) : 0);
        }
        roots.resize(n / 2);
        for (int i = 0; i < n / 2; ++i) {
            double ang = -2.0 * PI * i / n;
            roots[i] = cd(cos(ang), sin(ang));
        }
    }

    void transform(vector<cd>& a, bool inverse) const {
        for (int i = 0; i < n; ++i) {
            if (i < rev[i]) swap(a[i], a[rev[i]]);
        }
        for (int len = 2; len <= n; len <<= 1) {
            int step = n / len;
            int half = len >> 1;
            for (int i = 0; i < n; i += len) {
                for (int j = 0; j < half; ++j) {
                    cd w = roots[j * step];
                    if (inverse) w = conj(w);
                    cd u = a[i + j];
                    cd v = a[i + j + half] * w;
                    a[i + j] = u + v;
                    a[i + j + half] = u - v;
                }
            }
        }
        if (inverse) {
            double inv = 1.0 / n;
            for (cd& x : a) x *= inv;
        }
    }
};

struct Solver {
    int M;
    ll budget;
    vector<ll> cost;
    vector<int> w, d;
    FFT fft;
    chrono::steady_clock::time_point startTime;
    mt19937 rng{123456789};

    ll totalW = 0, upperBound = 0;
    vector<char> bestA;
    ll bestValue = -1, bestSpent = 0;

    vector<char> A;
    vector<int> c;
    ll value = 0, spent = 0;
    int k = 0;

    Solver(int m, ll b, const vector<ll>& co, const vector<int>& ww,
           const vector<int>& dd, chrono::steady_clock::time_point st)
        : M(m), budget(b), cost(co), w(ww), d(dd), fft(m), startTime(st) {
        for (int x : w) totalW += x;
        for (int i = 0; i < M; ++i) upperBound += (ll)w[i] * d[i];
    }

    double elapsed() const {
        return chrono::duration<double>(chrono::steady_clock::now() - startTime).count();
    }

    inline ll utility(int r, int cnt) const {
        return (ll)w[r] * min(cnt, d[r]);
    }

    void consider() {
        if (value > bestValue || (value == bestValue && spent < bestSpent)) {
            bestValue = value;
            bestSpent = spent;
            bestA = A;
        }
    }

    void computeCounts() {
        vector<int> S;
        bool useA = (k <= M - k);
        S.reserve(min(k, M - k));
        for (int i = 0; i < M; ++i) {
            if ((bool)A[i] == useA) S.push_back(i);
        }

        int s = (int)S.size();
        c.assign(M, s);

        if (s == 0) return;

        if (1LL * s * s <= 4LL * M || s <= 32) {
            for (int x : S) {
                for (int y : S) {
                    --c[(x + y) % M];
                }
            }
            return;
        }

        vector<cd> fa(fft.n, cd(0, 0));
        for (int x : S) fa[x] = cd(1, 0);
        fft.transform(fa, false);
        vector<cd> y(fft.n);
        for (int i = 0; i < fft.n; ++i) y[i] = fa[i] * fa[i];
        fft.transform(y, true);

        for (int r = 0; r < M; ++r) {
            ll t = llround(y[r].real() + y[r + M].real());
            int cr = s - (int)t;
            if (cr < 0) cr = 0;
            if (cr > s) cr = s;
            c[r] = cr;
        }
    }

    void initializeState(const vector<char>& start) {
        A = start;
        spent = 0;
        k = 0;
        for (int i = 0; i < M; ++i) {
            if (A[i]) {
                ++k;
                spent += cost[i];
            }
        }
        computeCounts();
        value = 0;
        for (int r = 0; r < M; ++r) value += utility(r, c[r]);
        consider();
    }

    ll flipPort(int p) {
        bool removing = A[p];
        ll delta = 0;

        if (!removing) {
            for (int q = 0; q < M; ++q) {
                if (q == p) continue;
                int r = (p + q) % M;
                int dc = A[q] ? -1 : 1;
                int old = c[r];
                int nw = old + dc;
                delta += utility(r, nw) - utility(r, old);
                c[r] = nw;
            }
            A[p] = 1;
            ++k;
            spent += cost[p];
        } else {
            for (int q = 0; q < M; ++q) {
                if (q == p) continue;
                int r = (p + q) % M;
                int dc = A[q] ? 1 : -1;
                int old = c[r];
                int nw = old + dc;
                delta += utility(r, nw) - utility(r, old);
                c[r] = nw;
            }
            A[p] = 0;
            --k;
            spent -= cost[p];
        }

        value += delta;
        return delta;
    }

    void computeGains(vector<ll>& gain) {
        vector<ll> G(M), L(M);
        ll sumG = 0, sumL = 0;
        for (int r = 0; r < M; ++r) {
            G[r] = (c[r] < d[r]) ? w[r] : 0;
            L[r] = (c[r] <= d[r]) ? w[r] : 0;
            sumG += G[r];
            sumL += L[r];
        }

        bool useA = (k <= M - k);
        vector<int> S;
        S.reserve(min(k, M - k));
        for (int i = 0; i < M; ++i) {
            if ((bool)A[i] == useA) S.push_back(i);
        }

        vector<ll> corrG(M, 0), corrL(M, 0);
        int s = (int)S.size();

        if (1LL * s * M <= 3000000LL) {
            for (int p = 0; p < M; ++p) {
                ll sg = 0, sl = 0;
                for (int q : S) {
                    int r = p + q;
                    if (r >= M) r -= M;
                    sg += G[r];
                    sl += L[r];
                }
                corrG[p] = sg;
                corrL[p] = sl;
            }
        } else {
            vector<cd> fs(fft.n, cd(0, 0)), z(fft.n, cd(0, 0));
            for (int q : S) fs[q] = cd(1, 0);
            for (int r = 0; r < M; ++r) {
                z[r] = cd((double)G[r], (double)L[r]);
            }
            fft.transform(fs, false);
            fft.transform(z, false);
            for (int i = 0; i < fft.n; ++i) z[i] = conj(fs[i]) * z[i];
            fft.transform(z, true);

            for (int p = 0; p < M; ++p) {
                int other = fft.n + p - M;
                double sg = z[p].real() + z[other].real();
                double sl = z[p].imag() + z[other].imag();
                ll cg = llround(sg);
                ll cl = llround(sl);
                cg = max(0LL, min(sumG, cg));
                cl = max(0LL, min(sumL, cl));
                corrG[p] = cg;
                corrL[p] = cl;
            }
        }

        gain.resize(M);
        for (int p = 0; p < M; ++p) {
            int twice = (int)((2LL * p) % M);
            if (useA) {
                if (A[p]) {
                    gain[p] = corrG[p] - G[twice] - (sumL - corrL[p]);
                } else {
                    gain[p] = sumG - corrG[p] - G[twice] - corrL[p];
                }
            } else {
                if (A[p]) {
                    gain[p] = sumG - corrG[p] - G[twice] - corrL[p];
                } else {
                    gain[p] = corrG[p] - G[twice] - (sumL - corrL[p]);
                }
            }
        }
    }

    ll evaluateSwap(int rem, int add) {
        ll removeDelta = 0;

        for (int q = 0; q < M; ++q) {
            if (q == rem) continue;
            int r = (rem + q) % M;
            int dc = A[q] ? 1 : -1;
            int old = c[r];
            int nw = old + dc;
            removeDelta += utility(r, nw) - utility(r, old);
            c[r] = nw;
        }

        A[rem] = 0;
        ll addDelta = 0;

        for (int q = 0; q < M; ++q) {
            if (q == add) continue;
            int r = (add + q) % M;
            if (A[q]) {
                if (c[r] <= d[r]) addDelta -= w[r];
            } else {
                if (c[r] < d[r]) addDelta += w[r];
            }
        }

        for (int q = 0; q < M; ++q) {
            if (q == rem) continue;
            int r = (rem + q) % M;
            int dc = A[q] ? 1 : -1;
            c[r] -= dc;
        }
        A[rem] = 1;

        return removeDelta + addDelta;
    }

    pair<int, int> findSwap(const vector<ll>& gain, double deadline) {
        if (k == 0 || k == M) return {-1, -1};

        ll maxCostA = 0;
        vector<int> additions;
        additions.reserve(M - k);

        for (int i = 0; i < M; ++i) {
            if (A[i]) maxCostA = max(maxCostA, cost[i]);
        }
        for (int j = 0; j < M; ++j) {
            if (!A[j] && spent - maxCostA + cost[j] <= budget) {
                additions.push_back(j);
            }
        }
        if (additions.empty()) return {-1, -1};

        sort(additions.begin(), additions.end(), [&](int x, int y) {
            if (gain[x] != gain[y]) return gain[x] > gain[y];
            if (cost[x] != cost[y]) return cost[x] < cost[y];
            return x < y;
        });
        if ((int)additions.size() > 28) additions.resize(28);

        struct Candidate {
            ll approximate;
            int rem, add;
        };
        vector<Candidate> candidates;

        for (int add : additions) {
            int best1 = -1, best2 = -1;
            for (int rem = 0; rem < M; ++rem) {
                if (!A[rem]) continue;
                if (spent - cost[rem] + cost[add] > budget) continue;

                auto better = [&](int x, int y) {
                    if (y == -1) return true;
                    if (gain[x] != gain[y]) return gain[x] > gain[y];
                    return cost[x] > cost[y];
                };

                if (better(rem, best1)) {
                    best2 = best1;
                    best1 = rem;
                } else if (better(rem, best2)) {
                    best2 = rem;
                }
            }
            if (best1 != -1) {
                candidates.push_back({gain[best1] + gain[add], best1, add});
            }
            if (best2 != -1) {
                candidates.push_back({gain[best2] + gain[add], best2, add});
            }
        }

        sort(candidates.begin(), candidates.end(), [](const Candidate& x, const Candidate& y) {
            return x.approximate > y.approximate;
        });

        ll bestDelta = 0;
        pair<int, int> answer{-1, -1};
        int evaluated = 0;

        for (const Candidate& cand : candidates) {
            if (evaluated >= 24) break;
            if ((evaluated & 3) == 0 && elapsed() >= deadline) break;
            ++evaluated;

            ll delta = evaluateSwap(cand.rem, cand.add);
            if (delta > bestDelta) {
                bestDelta = delta;
                answer = {cand.rem, cand.add};
            }
        }
        return answer;
    }

    void localSearch(const vector<char>& start, double deadline) {
        if (elapsed() >= deadline) return;
        initializeState(start);
        if (bestValue >= upperBound) return;

        vector<ll> gain;

        while (elapsed() < deadline) {
            computeGains(gain);

            int bestPort = -1;
            ll bestGain = 0;

            for (int p = 0; p < M; ++p) {
                if (!A[p] && spent + cost[p] > budget) continue;
                ll g = gain[p];
                if (g <= 0) continue;

                bool take = false;
                if (g > bestGain) {
                    take = true;
                } else if (g == bestGain && bestPort != -1) {
                    bool curRemove = A[p], oldRemove = A[bestPort];
                    if (curRemove != oldRemove) {
                        take = !curRemove;
                    } else if (!curRemove) {
                        take = cost[p] < cost[bestPort];
                    } else {
                        take = cost[p] > cost[bestPort];
                    }
                } else if (bestPort == -1) {
                    take = true;
                }

                if (take) {
                    bestGain = g;
                    bestPort = p;
                }
            }

            if (bestPort != -1) {
                ll oldValue = value;
                flipPort(bestPort);
                if (value <= oldValue) {
                    flipPort(bestPort);
                    return;
                }
                consider();
                if (bestValue >= upperBound) return;
                continue;
            }

            pair<int, int> sw = findSwap(gain, deadline);
            if (sw.first == -1) return;

            ll oldValue = value;
            flipPort(sw.first);
            flipPort(sw.second);

            if (value <= oldValue) {
                flipPort(sw.second);
                flipPort(sw.first);
                return;
            }

            consider();
            if (bestValue >= upperBound) return;
        }
    }

    void printAnswer() const {
        int count = 0;
        for (char x : bestA) count += x;
        cout << count << '\n';
        bool first = true;
        for (int i = 0; i < M; ++i) {
            if (bestA[i]) {
                if (!first) cout << ' ';
                first = false;
                cout << i;
            }
        }
        if (count) cout << '\n';
    }

    void run() {
        const double hardDeadline = 7.15;

        vector<char> singleA(M, 0);
        int singlePort = -1;
        ll singleValue = -1;

        for (int p = 0; p < M; ++p) {
            if (cost[p] > budget) continue;
            ll v = totalW - w[(2LL * p) % M];
            if (v > singleValue ||
                (v == singleValue && (singlePort == -1 || cost[p] < cost[singlePort]))) {
                singleValue = v;
                singlePort = p;
            }
        }

        singleA[singlePort] = 1;
        bestA = singleA;
        bestValue = singleValue;
        bestSpent = cost[singlePort];

        if (bestValue >= upperBound) {
            printAnswer();
            return;
        }

        vector<int> baseOrder(M);
        iota(baseOrder.begin(), baseOrder.end(), 0);
        sort(baseOrder.begin(), baseOrder.end(), [&](int x, int y) {
            if (cost[x] != cost[y]) return cost[x] < cost[y];
            return x < y;
        });

        vector<char> baseline(M, 0);
        ll baselineSpent = 0;
        for (int p : baseOrder) {
            if (baselineSpent + cost[p] <= budget) {
                baseline[p] = 1;
                baselineSpent += cost[p];
            }
        }

        localSearch(baseline, hardDeadline);

        if (bestValue >= upperBound || elapsed() >= hardDeadline) {
            printAnswer();
            return;
        }

        double now = elapsed();
        double remaining = hardDeadline - now;
        if (remaining > 0.08) {
            localSearch(singleA, now + remaining * 0.45);
        }

        int restart = 0;
        while (bestValue < upperBound && elapsed() + 0.05 < hardDeadline) {
            vector<char> start;
            ll startSpent = 0;

            if ((restart & 1) == 0) {
                start = bestA;
                vector<int> emitters;
                for (int i = 0; i < M; ++i) {
                    if (start[i]) {
                        emitters.push_back(i);
                        startSpent += cost[i];
                    }
                }

                if ((int)emitters.size() > 1) {
                    shuffle(emitters.begin(), emitters.end(), rng);
                    int maxRemove = min((int)emitters.size() - 1, 6);
                    int removeCount = 1 + (int)(rng() % maxRemove);
                    for (int t = 0; t < removeCount; ++t) {
                        int p = emitters[t];
                        start[p] = 0;
                        startSpent -= cost[p];
                    }
                } else if ((rng() & 1) && M > 1) {
                    for (int attempt = 0; attempt < 40; ++attempt) {
                        int p = rng() % M;
                        if (cost[p] <= budget) {
                            fill(start.begin(), start.end(), 0);
                            start[p] = 1;
                            startSpent = cost[p];
                            break;
                        }
                    }
                }

                int randomAdds = rng() % 3;
                int added = 0;
                for (int attempt = 0; attempt < 40 && added < randomAdds; ++attempt) {
                    int p = rng() % M;
                    if (!start[p] && startSpent + cost[p] <= budget) {
                        start[p] = 1;
                        startSpent += cost[p];
                        ++added;
                    }
                }
            } else {
                vector<int> order = baseOrder;
                int block = 16 + rng() % 32;
                for (int l = 0; l < M; l += block) {
                    int r = min(M, l + block);
                    shuffle(order.begin() + l, order.begin() + r, rng);
                }

                start.assign(M, 0);
                for (int p : order) {
                    if (startSpent + cost[p] <= budget) {
                        start[p] = 1;
                        startSpent += cost[p];
                    }
                }
            }

            now = elapsed();
            remaining = hardDeadline - now;
            if (remaining <= 0.04) break;
            double slice = min(remaining, M > 50000 ? 0.85 : 0.45);
            localSearch(start, now + slice);
            ++restart;
        }

        printAnswer();
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    auto programStart = chrono::steady_clock::now();

    int M;
    ll budget;
    cin >> M >> budget;

    vector<ll> cost(M);
    vector<int> w(M), d(M);
    for (ll& x : cost) cin >> x;
    for (int& x : w) cin >> x;
    for (int& x : d) cin >> x;

    if (M <= 20) {
        int total = 1 << M;
        vector<ll> costSum(total, 0);
        ll bestValue = -1;
        int bestMask = 0;
        vector<int> c(M);

        for (int mask = 1; mask < total; ++mask) {
            int bit = __builtin_ctz(mask);
            int previous = mask & (mask - 1);
            costSum[mask] = costSum[previous] + cost[bit];
            if (costSum[mask] > budget) continue;

            fill(c.begin(), c.end(), 0);
            for (int i = 0; i < M; ++i) {
                if (!(mask & (1 << i))) continue;
                for (int j = 0; j < M; ++j) {
                    if (!(mask & (1 << j))) {
                        ++c[(i + j) % M];
                    }
                }
            }

            ll value = 0;
            for (int r = 0; r < M; ++r) {
                value += (ll)w[r] * min(c[r], d[r]);
            }
            if (value > bestValue) {
                bestValue = value;
                bestMask = mask;
            }
        }

        int count = __builtin_popcount((unsigned)bestMask);
        cout << count << '\n';
        bool first = true;
        for (int i = 0; i < M; ++i) {
            if (bestMask & (1 << i)) {
                if (!first) cout << ' ';
                first = false;
                cout << i;
            }
        }
        if (count) cout << '\n';
        return 0;
    }

    Solver solver(M, budget, cost, w, d, programStart);
    solver.run();
    return 0;
}