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

题目 › abc400_g

Patisserie ABC 3

AtCoder ABC 400 G 题 · 2025-04-05 · 困难

N 个蛋糕各有三项属性,从中组成 K 对,每对的价格是两者三项属性分别相加后的最大值;求 K 对总价格的最大值。

查看原题

结果

Kimi K3.1 ProKimi

✓

通过

  • 官方测试 6/6判题
  • 43.4k输出 token(含思考) ↓
  • 735 秒延迟 ↓
  • 0.16 秒(最快)最慢测试的 CPU 时间 ↓
  • 32 MB峰值内存 ↓
  • 7Pylint 问题 ↓
  • 9.19Pylint 得分 ↑
  • 36圈复杂度 ↓
  • 51.6可维护性指数 ↑
  • 90有效行
  • 1SonarQube 问题 ↓

DeepSeek-V4.1-FlashDS-Flash

✓

通过

  • 官方测试 6/6判题
  • 55.0k输出 token(含思考) ↓
  • 334 秒延迟 ↓
  • 0.27 秒最慢测试的 CPU 时间 ↓
  • 40 MB峰值内存 ↓
  • 24Pylint 问题 ↓
  • 8.56Pylint 得分 ↑
  • 68圈复杂度 ↓
  • 33.9可维护性指数 ↑
  • 172有效行
  • 3SonarQube 问题 ↓

DeepSeek-V4-ProDS-Pro

✓

通过

  • 官方测试 6/6判题
  • 112.7k输出 token(含思考) ↓
  • 941 秒延迟 ↓
  • 1.45 秒(9.3×)最慢测试的 CPU 时间 ↓
  • 40 MB峰值内存 ↓
  • 54Pylint 问题 ↓
  • 6.82Pylint 得分 ↑
  • 24圈复杂度 ↓
  • 25.5可维护性指数 ↑
  • 170有效行
  • 3SonarQube 问题 ↓

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

代码

Kimi K3.1 Pro · 119 行
import sys


def solve():
    it = iter(map(int, sys.stdin.buffer.read().split()))
    test_count = next(it)
    answers = []
    INF = 10 ** 30

    for _ in range(test_count):
        n = next(it)
        k = next(it)
        values = []
        maximum = []
        base_color = []

        for _ in range(n):
            x = next(it)
            y = next(it)
            z = next(it)
            values.append((x, y, z))

            if x >= y and x >= z:
                maximum.append(x)
                base_color.append(0)
            elif y >= z:
                maximum.append(y)
                base_color.append(1)
            else:
                maximum.append(z)
                base_color.append(2)

        order = sorted(range(n), key=maximum.__getitem__, reverse=True)
        chosen_count = 2 * k
        chosen = order[:chosen_count]
        unchosen = order[chosen_count:]

        upper_bound = sum(maximum[i] for i in chosen)
        counts = [0, 0, 0]
        for i in chosen:
            counts[base_color[i]] += 1

        odd_colors = [c for c in range(3) if counts[c] & 1]
        if not odd_colors:
            answers.append(str(upper_bound))
            continue

        # Keep the two best candidates. Two changes can conflict on at most
        # one chosen cake and at most one unchosen cake.
        def add_two(lst, item):
            if len(lst) < 2:
                lst.append(item)
                lst.sort()
            elif item < lst[1]:
                lst[1] = item
                lst.sort()

        # recolor[a][b]: (loss, cake), for chosen cakes whose base color is a.
        recolor = [[[] for _ in range(3)] for _ in range(3)]
        # lowest[a]: two smallest maximum values among chosen cakes of color a.
        lowest = [[] for _ in range(3)]
        # highest[b]: two largest b-values among unchosen cakes, negated.
        highest = [[] for _ in range(3)]

        for i in chosen:
            a = base_color[i]
            mi = maximum[i]
            add_two(lowest[a], (mi, i))
            for b in range(3):
                if a != b:
                    add_two(recolor[a][b], (mi - values[i][b], i))

        for j in unchosen:
            for b in range(3):
                add_two(highest[b], (-values[j][b], j))

        # A change is (loss, chosen_cake, unchosen_cake).
        # unchosen_cake == -1 means a recoloring; otherwise it is a swap.
        changes = {}
        for a in range(3):
            for b in range(3):
                if a == b:
                    continue
                current = [(loss, i, -1) for loss, i in recolor[a][b]]
                for mi, i in lowest[a]:
                    for neg_value, j in highest[b]:
                        current.append((mi + neg_value, i, j))
                changes[(a, b)] = current

        a, b = odd_colors
        c = 3 - a - b
        best_loss = INF

        # One change toggling the two odd colors.
        for direction in ((a, b), (b, a)):
            for loss, _, _ in changes[direction]:
                best_loss = min(best_loss, loss)

        # Or two changes whose combined parity effect is the same.
        for d1 in ((a, c), (c, a)):
            for d2 in ((b, c), (c, b)):
                for first in changes[d1]:
                    for second in changes[d2]:
                        if first[1] == second[1]:
                            continue
                        if (first[2] != -1 and second[2] != -1
                                and first[2] == second[2]):
                            continue
                        best_loss = min(
                            best_loss, first[0] + second[0]
                        )

        answers.append(str(upper_bound - best_loss))

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


if __name__ == "__main__":
    solve()