题目 › usaco-1592

Point Elimination

USACO 2026 Third · 银组 · 2026-02 · L2 中等 · Python 3.11 · 时限 4 秒 · 测试点等分

查看原题跳到结果

题面

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

You have $N$ ($2 \leq N \leq 10^5, N$ is even$)$ points $(x_i,y_i)$ ($1 \leq x_i, y_i \leq 10^6$) on an infinite 2D-coordinate plane.

You can perform the following two types of operations any number of times:

  • Choose two points that are directly adjacent to each other (manhattan distance of $1$), and remove both points.
  • Choose any two points and swap their y-coordinates. Formally, points $(a,b)$ and $(c,d)$ become $(a,d)$ and $(c,b)$ respectively.

Determine if it is possible to eliminate all points on the board. Note that it may be the case that two points may map to the same coordinate; they should still be treated as different points. You also may not directly delete points on the same coordinate, as they are technically not directly adjacent.

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

The first line contains $T$ ($1 \leq T \leq 5000$), the number of test cases.

The first line of each test case contains an integer $N$.

The following $N$ lines contain two integers $x_i$ and $y_i$.

It is guaranteed that the sum of $N$ over all test cases does not exceed $5\cdot 10^5$.

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

For each test case, output "YES" or "NO" on a new line.

SAMPLE INPUT:

4
2
1 1
1 1
4
6 10
7 11
8 1
8 1
6
1 2
1 3
1 4
1 5
10 10
11 10
6
1 1
1 1
1 1
1 1
10 10
11 11

SAMPLE OUTPUT:

NO
YES
YES
NO

For the first test, the only two points are equal, so no swaps will do anything. Thus, our answer is NO.

In the second test, we can swap the y-coordinates of 6 and 7 with 8 and 8. Then, we can remove the first two points (horizontal adjacency) and the last two (vertical).

For the third test, no swaps are needed. We can remove the first pair, second, and third.

In the last test, it can be shown that no matter how we swap the y-coordinates, we will never be able to remove all the points in adjacent pairs.

SCORING:

  • Input 2: $T\le 1000$, $N \le 6$
  • Inputs 3-5: $N\le 100$
  • Inputs 6-11: No additional constraints.

Problem credits: Alex Pylypenko, Chongtian Ma

结果

Kimi K3.1 ProKimi

auto(max)

1/1

解出的采样 ↑

  • 100采样 1 · 解出
  • 28.8k平均输出 token(含思考) ↓
  • 27.9输出速度 tokens/s ↑
  • 1034 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • 无官方解时间复杂度(相对官方解)
  • 5Pylint 问题 ↓
  • 9.31Pylint 得分 ↑
  • 21圈复杂度 ↓
  • 35.7可维护性指数 ↑

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

1/1

解出的采样 ↑

  • 100采样 1 · 解出
  • 29.0k平均输出 token(含思考) ↓
  • 211.9输出速度 tokens/s ↑
  • 138 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • 无官方解时间复杂度(相对官方解)
  • 6Pylint 问题 ↓
  • 9.37Pylint 得分 ↑
  • 28圈复杂度 ↓
  • 30.9可维护性指数 ↑

MiniMax M3.1 FlashMiniMax

auto(max)

1/1

解出的采样 ↑

  • 100采样 1 · 解出
  • 48.7k平均输出 token(含思考) ↓
  • 155.5输出速度 tokens/s ↑
  • 314 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • 无官方解时间复杂度(相对官方解)
  • 3Pylint 问题 ↓
  • 9.58Pylint 得分 ↑
  • 16圈复杂度 ↓
  • 61.9可维护性指数 ↑

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

代码

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


def analyze(coords):
    coords.sort()
    values = []
    counts = []

    for value in coords:
        if values and values[-1] == value:
            counts[-1] += 1
        else:
            values.append(value)
            counts.append(1)

    total_p = 0
    total_f = 0
    g = len(values)
    i = 0

    while i < g:
        j = i
        run_size = counts[i]

        while j + 1 < g and values[j + 1] == values[j] + 1:
            j += 1
            run_size += counts[j]

        if run_size & 1:
            return None

        previous_p = 0
        remaining = 0

        for k in range(i, j + 1):
            c = counts[k]

            if k == j:
                p = 0
            else:
                p = (c - previous_p) & 1
                total_p += p

            reduced = c - previous_p - p
            if reduced < 0 or (reduced & 1):
                return None

            capacity = reduced // 2

            if k == i:
                remaining = capacity
            else:
                used = min(remaining, capacity)
                total_f += used
                remaining = capacity - used

            previous_p = p

        i = j + 1

    return total_p, total_f


def main():
    data = sys.stdin.buffer.read().split()
    t = int(data[0])
    pos = 1
    answers = []

    for _ in range(t):
        n = int(data[pos])
        pos += 1

        xs = [0] * n
        ys = [0] * n

        for i in range(n):
            xs[i] = int(data[pos])
            ys[i] = int(data[pos + 1])
            pos += 2

        x_info = analyze(xs)
        if x_info is None:
            answers.append("NO")
            continue

        y_info = analyze(ys)
        if y_info is None:
            answers.append("NO")
            continue

        px, fx = x_info
        py, fy = y_info

        difference = n // 2 - px - py
        possible = (
            difference >= 0
            and difference % 2 == 0
            and difference // 2 <= fx + fy
        )

        answers.append("YES" if possible else "NO")

    sys.stdout.write("\n".join(answers))


if __name__ == "__main__":
    main()