题面
来源: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
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 28.8k平均输出 token(含思考) ↓
- 27.9输出速度 tokens/s ↑
- 1034 秒延迟 ↓
- —CPU 时间 / 官方解 ↓
- 无官方解时间复杂度(相对官方解)
- 5Pylint 问题 ↓
- 9.31Pylint 得分 ↑
- 21圈复杂度 ↓
- 35.7可维护性指数 ↑
DeepSeek Flash V4.1-1017DeepSeek
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 29.0k平均输出 token(含思考) ↓
- 211.9输出速度 tokens/s ↑
- 138 秒延迟 ↓
- —CPU 时间 / 官方解 ↓
- 无官方解时间复杂度(相对官方解)
- 6Pylint 问题 ↓
- 9.37Pylint 得分 ↑
- 28圈复杂度 ↓
- 30.9可维护性指数 ↑
MiniMax M3.1 FlashMiniMax
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 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
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()
import sys def get_interval(arr): n = len(arr) arr.sort() groups = [] for v in arr: if not groups or groups[-1][0] != v: groups.append([v, 1]) else: groups[-1][1] += 1 total_pairs = n // 2 k_min_total = 0 k_max_total = 0 idx = 0 g_len = len(groups) while idx < g_len: j = idx counts = [groups[idx][1]] while j + 1 < g_len and groups[j + 1][0] == groups[j][0] + 1: j += 1 counts.append(groups[j][1]) m = len(counts) p_edges = [] p_prev = 0 ok = True for t in range(m - 1): p = (counts[t] - p_prev) & 1 if p_prev + p > counts[t]: ok = False break p_edges.append(p) p_prev = p if not ok: return None if (counts[-1] - p_prev) % 2 != 0 or p_prev > counts[-1]: return None capacities = [] for t in range(m): left = p_edges[t - 1] if t > 0 else 0 right = p_edges[t] if t < m - 1 else 0 used = left + right if used > counts[t] or (counts[t] - used) % 2 != 0: return None capacities.append((counts[t] - used) // 2) k_min = sum(p_edges) prev = 0 extra = 0 for t in range(m - 1): remaining = capacities[t] - prev take = remaining if remaining < capacities[t + 1] else capacities[t + 1] extra += take prev = take if prev > capacities[-1]: return None k_max = k_min + 2 * extra k_min_total += k_min k_max_total += k_max idx = j + 1 low_equal = total_pairs - k_max_total high_equal = total_pairs - k_min_total return low_equal, high_equal def solve(): data = list(map(int, sys.stdin.buffer.read().split())) if not data: return t = data[0] pos = 1 answers = [] for _ in range(t): n = data[pos] pos += 1 xs = [0] * n ys = [0] * n for i in range(n): xs[i] = data[pos] ys[i] = data[pos + 1] pos += 2 rx = get_interval(xs) if rx is None: answers.append("NO") continue ry = get_interval(ys) if ry is None: answers.append("NO") continue lx, hx = rx ly, hy = ry target = n // 2 low_sum = lx + ly high_sum = hx + hy if low_sum <= target <= high_sum and (target - low_sum) % 2 == 0: answers.append("YES") else: answers.append("NO") sys.stdout.write("\n".join(answers)) if __name__ == "__main__": solve()
import sys def possible_edge_sums(counts): """ For each maximal component of consecutive occupied coordinates, consider edge counts t_i satisfying: t_{i-1} + t_i <= count[i] t_{i-1} + t_i == count[i] (mod 2) Return (minimum, maximum) such that every value between them with the same parity as minimum is attainable. Return None if a component has an odd total. """ coordinates = sorted(counts) size = len(coordinates) lower = 0 upper = 0 start = 0 while start < size: index = start prefix_parity = 0 left_edge_parity = 0 component_lower = 0 # Minimum-weight vertex-cover DP on the residual-capacity path. # These are also the maximum additional edge counts by the # capacitated bipartite matching / weighted vertex-cover theorem. dp_excluded = 0 dp_included = 0 while index < size: coordinate = coordinates[index] if index > start and coordinate != coordinates[index - 1] + 1: break amount = counts[coordinate] prefix_parity ^= (amount & 1) right_edge_parity = prefix_parity residual = ( amount - left_edge_parity - right_edge_parity ) // 2 next_excluded = dp_included if dp_excluded < dp_included: next_included = dp_excluded + residual else: next_included = dp_included + residual dp_excluded = next_excluded dp_included = next_included # The final edge of an even-sized component has parity zero, # so this also counts exactly the internal edges. component_lower += right_edge_parity left_edge_parity = right_edge_parity index += 1 # An odd number of points in a coordinate component cannot be # partitioned into pairs entirely within that component. if prefix_parity: return None extra_maximum = ( dp_excluded if dp_excluded < dp_included else dp_included ) lower += component_lower upper += component_lower + 2 * extra_maximum start = index return lower, upper def solve(): tokens = iter(map(int, sys.stdin.buffer.read().split())) try: test_cases = next(tokens) except StopIteration: return answers = [] for _ in range(test_cases): n = next(tokens) x_counts = {} y_counts = {} for _ in range(n): x = next(tokens) y = next(tokens) x_counts[x] = x_counts.get(x, 0) + 1 y_counts[y] = y_counts.get(y, 0) + 1 # Number of possible horizontal pairs. x_limits = possible_edge_sums(x_counts) if x_limits is None: answers.append("NO") continue # Number of possible vertical pairs. y_limits = possible_edge_sums(y_counts) if y_limits is None: answers.append("NO") continue minimum = x_limits[0] + y_limits[0] maximum = x_limits[0] + y_limits[1] maximum = x_limits[1] + y_limits[1] required_pairs = n // 2 possible = ( minimum <= required_pairs <= maximum and (required_pairs - minimum) % 2 == 0 ) answers.append("YES" if possible else "NO") sys.stdout.write("\n".join(answers)) if __name__ == "__main__": solve()