题目 › usaco-1469

Cow Checkups

USACO 2025 January · 铜组 · 2025-01 · L1 基础 · Python 3.11 · 时限 4 秒 · 测试点等分

查看原题跳到结果

题面

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

**Note: We suggest using a language other than Python to earn full credit on this problem.**

Farmer John's $N$ ($1 \leq N \leq 7500$) cows are standing in a line, with cow $1$ at the front of the line and cow $N$ at the back of the line. FJ's cows also come in many different species. He denotes each species with an integer from $1$ to $N$. The $i$'th cow from the front of the line is of species $a_i$ ($1 \leq a_i \leq N$).

FJ is taking his cows to a checkup at a local bovine hospital. However, the bovine veterinarian is very picky and wants to perform a checkup on the $i$'th cow in the line, only if it is of species $b_i$ ($1 \leq b_i \leq N$).

FJ is lazy and does not want to completely reorder his cows. He will perform the following operation exactly once.

  • Select two integers $l$ and $r$ such that $1 \leq l \le r \leq N$. Reverse the order of the cows that are between the $l$-th cow and the $r$-th cow in the line, inclusive.

FJ wants to measure how effective this approach is. For each $c=0 \ldots N$, help FJ find the number of distinct operations ($l,r$) that result in exactly $c$ cows being checked. Two operations ($l_1,r_1$) and ($l_2,r_2$) are different if $l_1 \neq l_2$ or $r_1 \neq r_2$.

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

The first line contains an integer $N$.

The second line contains $a_1, a_2, \ldots, a_N$.

The third line contains $b_1, b_2, \ldots, b_N$.

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

Output $N+1$ lines with the $i$-th line containing the number of distinct operations ($l,r$) that result in $i-1$ cows being checked.

SAMPLE INPUT:

3
1 3 2
3 2 1

SAMPLE OUTPUT:

3
3
0
0
If FJ chooses ($l=1,r=1$), ($l=2,r=2$), or ($l=3,r=3$) then no cows will be checked. Note that those operations do not modify any of the cows' locations.

The following operations result in one cow being checked.

  • $l=1,r=2$: FJ reverses the order of the first and second cows so the species of each cow in the new lineup will be $[3,1,2]$. The first cow will be checked.
  • $l=2,r=3$: FJ reverses the order of the second and third cows so the species of each cow in the new lineup will be $[1,2,3]$. The second cow will be checked.
  • $l=1,r=3$: FJ reverses the order of the first, second, and third cows so the species of each cow in the new lineup will be $[2,3,1]$. The third cow will be checked.

SAMPLE INPUT:

3
1 2 3
1 2 3

SAMPLE OUTPUT:

0
3
0
3
The three possible operations that cause $3$ cows to be checked are ($l=1,r=1$), ($l=2,r=2$), and ($l=3,r=3$).

SAMPLE INPUT:

7
1 3 2 2 1 3 2
3 2 2 1 2 3 1

SAMPLE OUTPUT:

0
6
14
6
2
0
0
0
The two possible operations that cause $4$ cows to be checked are ($l=4,r=5$) and ($l=5,r=7$).

SCORING:

  • Inputs 4-6: $N\le 100$
  • Inputs 7-13: No additional constraints

Problem credits: Chongtian Ma and Haokai Ma

结果

Kimi K3.1 ProKimi

auto(max)

0/1

解出的采样 ↑

  • 46.2采样 1 · 超时
  • 11.9k平均输出 token(含思考) ↓
  • 28.0输出速度 tokens/s ↑
  • 426 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • 无官方解时间复杂度(相对官方解)
  • 2Pylint 问题 ↓
  • 9.00Pylint 得分 ↑
  • 4圈复杂度 ↓
  • 74.1可维护性指数 ↑

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

0/1

解出的采样 ↑

  • 46.2采样 1 · 超时
  • 12.1k平均输出 token(含思考) ↓
  • 200.5输出速度 tokens/s ↑
  • 61 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • 无官方解时间复杂度(相对官方解)
  • 3Pylint 问题 ↓
  • 9.36Pylint 得分 ↑
  • 10圈复杂度 ↓
  • 54.8可维护性指数 ↑

MiniMax M3.1 FlashMiniMax

auto(max)

0/1

解出的采样 ↑

  • 84.6采样 1 · 超时
  • 45.2k平均输出 token(含思考) ↓
  • 145.1输出速度 tokens/s ↑
  • 313 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • 无官方解时间复杂度(相对官方解)
  • 3Pylint 问题 ↓
  • 9.55Pylint 得分 ↑
  • 11圈复杂度 ↓
  • 62.3可维护性指数 ↑

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

代码

Kimi K3.1 Pro · 采样 1 · 39 行
import sys


def main():
    data = list(map(int, sys.stdin.buffer.read().split()))
    n = data[0]
    a = data[1:n + 1]
    b = data[n + 1:]

    original_match = [x == y for x, y in zip(a, b)]
    base = sum(original_match)

    answer = [0] * (n + 1)

    # All n operations with l == r leave the line unchanged.
    answer[base] = n

    # Operations with l < r are grouped by l + r. On each such diagonal,
    # successive operations expand the previous reversed interval by one cow
    # on each side, so only the two new endpoints change the match count.
    for diagonal in range(1, 2 * n - 2):
        left = (diagonal - 1) // 2
        right = diagonal - left
        checked = base

        for l, r in zip(range(left, -1, -1), range(right, n)):
            checked += (
                (a[r] == b[l])
                + (a[l] == b[r])
                - original_match[l]
                - original_match[r]
            )
            answer[checked] += 1

    sys.stdout.write("\n".join(map(str, answer)) + "\n")


if __name__ == "__main__":
    main()