题目 › usaco-1572

Circle of Cows

USACO 2026 Second · 铂金组 · 2026-01 · L4 顶尖 · C++17 · 时限 2 秒 · 测试点等分

查看原题跳到结果

题面

来源:USACO 官网。模型收到的是同一份题面的文字。

Farmer John has $N$ ($2\le N\le 1000$) cows at distinct locations $l_1,\dots, l_N$ along a circle of circumference $C$ ($0\le l_1 < l_2 < \dots < l_N <C, N\le C\le 10^9$).

FJ will select $k$ pairs of cows, where $1\le k\le \lfloor N/2\rfloor$, and no cow is selected more than once. He wants to select the pairs such that the minimum distance between any two cows in the same pair along the circumference of the circle is maximized.

For each value of $k$, help FJ determine the maximum possible minimum distance.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains $N$ and $C$.

The second line contains $l_1\dots l_N$.

OUTPUT FORMAT (print output to the terminal / stdout):

Output a single line with $\lfloor N/2\rfloor$ space-separated integers, with the answers for $k=1\dots \lfloor N/2\rfloor$ in that order.

SAMPLE INPUT:

4 100
0 25 50 75

SAMPLE OUTPUT:

50 50

For $k = 1$, cow 1 can be paired to cow 3, which is distance $50$ away along the circumference of the circle, making the answer $50$.

For $k = 2$, cow 1 can be paired to cow 3, and cow 2 can be paired to cow 4, which is distance $50$ away from it along the circumference of the circle, making the answer still $50$.

SAMPLE INPUT:

4 100
0 1 2 99

SAMPLE OUTPUT:

3 2

For $k = 1$, cow 3 can be paired to cow 4, which is distance $2 + 100 - 99 = 3$ away from it along the circumference of the circle, making the answer $3$.

For $k = 2$, cow 1 can be paired to cow 3 and cow 2 can be paired to cow 4. Each of these pairs contains two cows at a distance of $2$ from each other along the circumference of the circle, making the answer $2$.

SCORING:

  • Inputs 3-4: $2l_N \le C$
  • Inputs 5-6: $N\le 20$
  • Inputs 7-14: $N\le 100$
  • Inputs 15-22: No additional constraints.

Problem credits: Benjamin Qi

结果

Kimi K3.1 ProKimi

max

1/3

解出的采样 ↑

  • 18.2采样 1 · 答案错误
  • 100采样 2 · 解出
  • 18.2采样 3 · 答案错误
  • 85.7k平均输出 token(含思考) ↓
  • 23.6输出速度 tokens/s ↑
  • 3573 秒延迟 ↓
  • 0.17×CPU 时间 / 官方解 ↓
  • 更优 1时间复杂度(相对官方解)

Kimi K3.1 Pro(high)Kimi high

high

0/3

解出的采样 ↑

  • 18.2采样 1 · 答案错误
  • 9.1采样 2 · 答案错误
  • 18.2采样 3 · 答案错误
  • 37.3k平均输出 token(含思考) ↓
  • 21.7输出速度 tokens/s ↑
  • 1630 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • —时间复杂度(相对官方解)

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

0/3

解出的采样 ↑

  • 27.3采样 1 · 答案错误
  • 77.3采样 2 · 超时
  • 18.2采样 3 · 答案错误
  • 104.3k平均输出 token(含思考) ↓
  • 165.3输出速度 tokens/s ↑
  • 675 秒延迟 ↓
  • 2.15×CPU 时间 / 官方解 ↓
  • 同阶 1时间复杂度(相对官方解)

MiniMax M3.1 FlashMiniMax

auto(max)

0/3

解出的采样 ↑

  • 18.2采样 1 · 答案错误
  • 18.2采样 2 · 答案错误
  • 18.2采样 3 · 答案错误
  • 140.5k平均输出 token(含思考) ↓
  • 128.0输出速度 tokens/s ↑
  • 1220 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • —时间复杂度(相对官方解)

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

代码

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

using int64 = long long;

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

    int N;
    int64 C;
    cin >> N >> C;

    vector<int64> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    vector<int64> x(2 * N);
    for (int i = 0; i < N; ++i) {
        x[i] = a[i];
        x[i + N] = a[i] + C;
    }

    const int64 INF = (1LL << 60);
    vector<int64> best(N + 1, INF);
    best[1] = 0;

    // For every cyclic interval of consecutive cows, compute its diameter.
    for (int start = 0; start < N; ++start) {
        int64 diameter = 0;

        for (int end = start + 1; end < start + N; ++end) {
            // Find the old cows immediately around the antipode of x[end].
            int lo = start, hi = end;
            const int64 threshold = 2 * x[end] - C;

            while (lo < hi) {
                int mid = (lo + hi) / 2;
                if (2 * x[mid] >= threshold) {
                    hi = mid;
                } else {
                    lo = mid + 1;
                }
            }

            auto update = [&](int idx) {
                if (idx < start || idx >= end) return;
                int64 d = x[end] - x[idx];
                diameter = max(diameter, min(d, C - d));
            };

            update(lo);
            update(lo - 1);

            int len = end - start + 1;
            best[len] = min(best[len], diameter);
        }
    }

    for (int k = 1; k <= N / 2; ++k) {
        if (k > 1) cout << ' ';
        int q = N - k + 1;
        cout << min(best[q], C / 2);
    }
    cout << '\n';

    return 0;
}