这是 2026-10-23 的上一版评测(LiveCodeBench 最新 35 题)。最新的阶梯评测见 首页。

题目 › arc195_b

Uniform Sum

AtCoder ARC 195 B 题 · 2025-03-23 · 困难

A、B 中的 -1 可替换为任意非负整数,A 可任意重排;判断能否使所有 Aᵢ + Bᵢ 相等。

查看原题

结果

Kimi K3.1 ProKimi

✓

通过

  • 官方测试 43/43判题
  • 54.6k输出 token(含思考) ↓
  • 924 秒延迟 ↓
  • 0.15 秒(最快)最慢测试的 CPU 时间 ↓
  • 14 MB峰值内存 ↓
  • 8Pylint 问题 ↓
  • 9.02Pylint 得分 ↑
  • 25圈复杂度 ↓
  • 56.2可维护性指数 ↑
  • 85有效行
  • 1SonarQube 问题 ↓

DeepSeek-V4.1-FlashDS-Flash

✓

通过

  • 官方测试 43/43判题
  • 16.7k输出 token(含思考) ↓
  • 96 秒延迟 ↓
  • 1.30 秒(8.5×)最慢测试的 CPU 时间 ↓
  • 91 MB峰值内存 ↓
  • 15Pylint 问题 ↓
  • 7.06Pylint 得分 ↑
  • 17圈复杂度 ↓
  • 41.8可维护性指数 ↑
  • 53有效行
  • 5SonarQube 问题 ↓

DeepSeek-V4-ProDS-Pro

✓

通过

  • 官方测试 43/43判题
  • 55.7k输出 token(含思考) ↓
  • 454 秒延迟 ↓
  • 0.96 秒(6.3×)最慢测试的 CPU 时间 ↓
  • 119 MB峰值内存 ↓
  • 25Pylint 问题 ↓
  • 6.99Pylint 得分 ↑
  • 24圈复杂度 ↓
  • 51.0可维护性指数 ↑
  • 83有效行
  • 5SonarQube 问题 ↓

↑ 越大越好,↓ 越小越好,有效行只描述代码长短。CPU 时间与内存只统计能区分性能的题(最慢答案扣除进程启动后仍 ≥ 0.1 秒),括号内为相对最快者的倍数(≥ 2 时标出)。静态质量按 arXiv:2610.19167 的口径(见 原理)。判题方法见 原理 › 判题。

代码

Kimi K3.1 Pro · 124 行
import sys
from bisect import bisect_left


def solve():
    it = iter(map(int, sys.stdin.buffer.read().split()))
    n = next(it)
    A = [next(it) for _ in range(n)]
    B = [next(it) for _ in range(n)]

    count_a = {}
    count_b = {}
    wild_a = 0
    wild_b = 0

    for x in A:
        if x == -1:
            wild_a += 1
        else:
            count_a[x] = count_a.get(x, 0) + 1

    for x in B:
        if x == -1:
            wild_b += 1
        else:
            count_b[x] = count_b.get(x, 0) + 1

    wild = wild_a + wild_b

    # All fixed elements can be paired with wildcards.
    if wild >= n:
        sys.stdout.write("Yes\n")
        return

    # In any feasible pairing, at least `need` pairs must consist of two
    # fixed values. All pairs in such a pairing must have the same sum.
    need = n - wild

    # The largest fixed A value and largest fixed B value always provide
    # one usable fixed-fixed pair.
    if need == 1:
        sys.stdout.write("Yes\n")
        return

    a_items = sorted(count_a.items())
    b_items = sorted(count_b.items())
    a_vals = [x for x, _ in a_items]
    b_vals = [x for x, _ in b_items]
    b_cnts = [c for _, c in b_items]
    u = len(a_items)
    v = len(b_items)

    # Every fixed value must not exceed the final common sum.
    min_sum = max(a_vals[-1], b_vals[-1])

    # Select more than q fixed A items (or more than p fixed B items).
    # At least one selected item must belong to a fixed-fixed pair in any
    # feasible configuration, so its pair sum is a sufficient candidate set.
    def make_core(items, amount):
        core = []
        covered = 0
        for value, cnt in sorted(items, key=lambda z: z[1], reverse=True):
            core.append(value)
            covered += cnt
            if covered >= amount:
                break
        return core

    core_a = make_core(a_items, wild_b + 1)
    core_b = make_core(b_items, wild_a + 1)

    candidates_a_size = 0
    for a in core_a:
        candidates_a_size += v - bisect_left(b_vals, min_sum - a)

    candidates_b_size = 0
    for b in core_b:
        candidates_b_size += u - bisect_left(a_vals, min_sum - b)

    candidates = {}

    if candidates_a_size <= candidates_b_size:
        for a in core_a:
            start = bisect_left(b_vals, min_sum - a)
            for j in range(start, v):
                candidates[a + b_vals[j]] = 0
    else:
        for b in core_b:
            start = bisect_left(a_vals, min_sum - b)
            for i in range(start, u):
                candidates[a_vals[i] + b] = 0

    if not candidates:
        sys.stdout.write("No\n")
        return

    # For a fixed sum s, different A values use different B values.
    # Therefore the maximum number of fixed-fixed pairs is
    #   sum_a min(count_a[a], count_b[s-a]).
    # Accumulate this quantity only for the sufficient candidate sums.
    get_candidate = candidates.get

    for a, acnt in a_items:
        start = bisect_left(b_vals, min_sum - a)
        for j in range(start, v):
            s = a + b_vals[j]
            current = get_candidate(s)
            if current is None:
                continue

            bcnt = b_cnts[j]
            current += acnt if acnt < bcnt else bcnt

            if current >= need:
                sys.stdout.write("Yes\n")
                return

            candidates[s] = current

    sys.stdout.write("No\n")


if __name__ == "__main__":
    solve()