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

题目 › 3777

Maximum Product of Subsequences with an Alternating Sum Equal to K

LeetCode 周赛 444 · 2025-04-05 · 困难

找一个交错和等于 k 的非空子序列,使其元素乘积在不超过 limit 的前提下最大;不存在时返回 -1。

查看原题

结果

Kimi K3.1 ProKimi

✓

通过

  • 函数调用,官方测试全部通过判题
  • 15.2k输出 token(含思考) ↓
  • 199 秒延迟 ↓
  • —最慢测试的 CPU 时间 ↓
  • —峰值内存 ↓
  • 7Pylint 问题 ↓
  • 8.16Pylint 得分 ↑
  • 31圈复杂度 ↓
  • 66.5可维护性指数 ↑
  • 39有效行
  • 2SonarQube 问题 ↓

DeepSeek-V4.1-FlashDS-Flash

✓

通过

  • 函数调用,官方测试全部通过判题
  • 13.9k输出 token(含思考) ↓
  • 79 秒延迟 ↓
  • —最慢测试的 CPU 时间 ↓
  • —峰值内存 ↓
  • 8Pylint 问题 ↓
  • 8.43Pylint 得分 ↑
  • 43圈复杂度 ↓
  • 58.9可维护性指数 ↑
  • 52有效行
  • 2SonarQube 问题 ↓

DeepSeek-V4-ProDS-Pro

✓

通过

  • 函数调用,官方测试全部通过判题
  • 50.8k输出 token(含思考) ↓
  • 388 秒延迟 ↓
  • —最慢测试的 CPU 时间 ↓
  • —峰值内存 ↓
  • 10Pylint 问题 ↓
  • 8.41Pylint 得分 ↑
  • 47圈复杂度 ↓
  • 56.7可维护性指数 ↑
  • 65有效行
  • 2SonarQube 问题 ↓

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

代码

Kimi K3.1 Pro · 58 行
from typing import List

class Solution:
    def maxProduct(self, nums: List[int], k: int, limit: int) -> int:
        total = sum(nums)
        if k < -total or k > total:
            return -1

        offset = total
        mask = (1 << (2 * total + 1)) - 1

        # Products greater than limit can share one state. Such a product can
        # only remain overflowed, or become 0 after multiplying by zero.
        over = limit + 1
        size = over + 1

        # even[p] / odd[p] store a bitset of alternating sums for nonempty
        # subsequences of even / odd length whose (capped) product is p.
        even = [0] * size
        odd = [0] * size

        for x in nums:
            old_even, old_odd = even, odd
            even = old_even.copy()
            odd = old_odd.copy()

            next_product = [0] * size
            if x:
                for p in range(size):
                    if p == over:
                        next_product[p] = over
                    else:
                        value = p * x
                        next_product[p] = value if value <= limit else over

            for p in range(size):
                q = next_product[p]

                bits = old_even[p]
                if bits:
                    # x is appended at an even index, so it is added.
                    odd[q] |= (bits << x) & mask

                bits = old_odd[p]
                if bits:
                    # x is appended at an odd index, so it is subtracted.
                    even[q] |= bits >> x

            # Start a new subsequence containing only x.
            singleton_product = x if x <= limit else over
            odd[singleton_product] |= 1 << (offset + x)

        target = 1 << (offset + k)
        for product in range(limit, -1, -1):
            if (even[product] & target) or (odd[product] & target):
                return product

        return -1