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

题目 › arc195_d

Swap and Erase

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

可以交换相邻元素,或删除开头一段全部相等的前缀;求删空序列的最少操作数。

要点:交换与删除的组合优化,须近线性时间(T ≤ 10⁵,ΣN ≤ 2×10⁵)。样例:(1,1,2,1,2) 为 3(1 次交换 + 2 次删除),(4,2,1,3) 为 4(不交换)。

查看原题

结果

Kimi K3.1 ProKimi

✓

通过

  • 官方测试 2/2判题
  • 86.5k输出 token(含思考) ↓
  • 1089 秒延迟 ↓
  • —最慢测试的 CPU 时间 ↓
  • —峰值内存 ↓
  • 3Pylint 问题 ↓
  • 9.27Pylint 得分 ↑
  • 16圈复杂度 ↓
  • 61.0可维护性指数 ↑
  • 53有效行
  • 1SonarQube 问题 ↓

DeepSeek-V4.1-FlashDS-Flash

✓

通过

  • 官方测试 2/2判题
  • 81.0k输出 token(含思考) ↓
  • 475 秒延迟 ↓
  • —最慢测试的 CPU 时间 ↓
  • —峰值内存 ↓
  • 7Pylint 问题 ↓
  • 7.74Pylint 得分 ↑
  • 12圈复杂度 ↓
  • 61.4可维护性指数 ↑
  • 32有效行
  • 1SonarQube 问题 ↓

DeepSeek-V4-ProDS-Pro

✓

通过

  • 官方测试 2/2判题
  • 110.3k输出 token(含思考) ↓
  • 815 秒延迟 ↓
  • —最慢测试的 CPU 时间 ↓
  • —峰值内存 ↓
  • 5Pylint 问题 ↓
  • 8.96Pylint 得分 ↑
  • 17圈复杂度 ↓
  • 55.6可维护性指数 ↑
  • 53有效行
  • 1SonarQube 问题 ↓

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

代码

Kimi K3.1 Pro · 72 行
import sys


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

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

        # Run-length encode the sequence.
        values = []
        counts = []
        for _ in range(n):
            x = data[pos]
            pos += 1
            if values and values[-1] == x:
                counts[-1] += 1
            else:
                values.append(x)
                counts.append(1)

        m = len(values)

        # dp[i]: answer for the contiguous suffix of runs i..m-1.
        # aux[i]: answer for run i followed by runs i+2..m-1
        #         (run i+1 is absent).
        dp = [0] * (m + 1)
        aux = [0] * m

        for i in range(m - 1, -1, -1):
            j = i + 2

            if j >= m:
                aux[i] = 1
            elif values[i] == values[j]:
                # The two equal-valued parts form one leading run. Its length
                # does not affect the answer.
                aux[i] = dp[j]
            else:
                best = 1 + dp[j]
                k = j + 1
                if (
                    k < m
                    and counts[j] == 1
                    and counts[k] == 1
                    and values[k] == values[i]
                ):
                    best = min(best, 2 + aux[j])
                aux[i] = best

            best = 1 + dp[i + 1]
            if (
                i + 2 < m
                and counts[i + 1] == 1
                and counts[i + 2] == 1
                and values[i + 2] == values[i]
            ):
                best = min(best, 2 + aux[i + 1])
            dp[i] = best

        answers.append(str(dp[0]))

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


if __name__ == "__main__":
    main()