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

题目 › 3805

Maximize Active Section with Trade I

LeetCode 双周赛 153 · 2025-03-29 · 中等

对 01 串至多做一次交易:先把一段两侧都是 0 的连续 1 全变成 0,再把一段两侧都是 1 的连续 0 全变成 1;求最终 1 的最大个数。

查看原题

结果

Kimi K3.1 ProKimi

✓

通过

  • 函数调用,官方测试全部通过判题
  • 7.5k输出 token(含思考) ↓
  • 94 秒延迟 ↓
  • —最慢测试的 CPU 时间 ↓
  • —峰值内存 ↓
  • 6Pylint 问题 ↓
  • 6.67Pylint 得分 ↑
  • 13圈复杂度 ↓
  • 77.4可维护性指数 ↑
  • 18有效行
  • 1SonarQube 问题 ↓

DeepSeek-V4.1-FlashDS-Flash

✓

通过

  • 函数调用,官方测试全部通过判题
  • 13.4k输出 token(含思考) ↓
  • 75 秒延迟 ↓
  • —最慢测试的 CPU 时间 ↓
  • —峰值内存 ↓
  • 12Pylint 问题 ↓
  • 4.29Pylint 得分 ↑
  • 11圈复杂度 ↓
  • 75.5可维护性指数 ↑
  • 22有效行
  • 1SonarQube 问题 ↓

DeepSeek-V4-ProDS-Pro

✓

通过

  • 函数调用,官方测试全部通过判题
  • 27.9k输出 token(含思考) ↓
  • 208 秒延迟 ↓
  • —最慢测试的 CPU 时间 ↓
  • —峰值内存 ↓
  • 6Pylint 问题 ↓
  • 7.27Pylint 得分 ↑
  • 17圈复杂度 ↓
  • 66.1可维护性指数 ↑
  • 22有效行
  • 1SonarQube 问题 ↓

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

代码

Kimi K3.1 Pro · 25 行
class Solution:
    def maxActiveSectionsAfterTrade(self, s: str) -> int:
        t = "1" + s + "1"

        # Compress t into alternating runs of identical characters.
        runs = []
        i = 0
        while i < len(t):
            j = i + 1
            while j < len(t) and t[j] == t[i]:
                j += 1
            runs.append((t[i], j - i))
            i = j

        initial = s.count("1")
        answer = initial

        # An internal '1' run can be removed. Filling the resulting zero run
        # gives a net gain equal to the lengths of its two adjacent zero runs.
        for i in range(1, len(runs) - 1):
            if runs[i][0] == "1":
                gain = runs[i - 1][1] + runs[i + 1][1]
                answer = max(answer, initial + gain)

        return answer