题目 › usaco-1590

Clash!

USACO 2026 Third · 银组 · 2026-02 · L2 中等 · Python 3.11 · 时限 4 秒 · 测试点等分

查看原题跳到结果

题面

来源:USACO 官网。模型收到的是同一份题面的文字。

Farmer John is playing a famous and strategic card game with his dear cow Bessie. FJ has $N$ ($2\le N\le 2\cdot 10^5$) cards, conveniently numbered from $1$ to $N$. The $i$'th card costs $a_i$ ($1 \leq a_i \leq 10^9$) moolixir if FJ wants to play it.

His hand always consists of $H$ cards at any given time ($1\le H<N$). Initially, his hand consists of cards $1$ through $H$. The remaining cards are in a draw queue. Every time FJ plays a card in his hand, he will draw its replacement from the front of the draw queue to his hand. Then, FJ will put the card he just played to the back of the draw queue. Initially, cards $H+1$ through $N$ are arranged from the front to the back of the draw queue in that order.

In this game, time is measured in integer seconds. Initially, the game starts at time $0$ with FJ having $0$ moolixir. Immediately before each of integer times $t=1,2,3,\dots,$ moolixir increases by $1$. At each integer time, FJ may choose to play a card in his hand if its cost does not exceed FJ's current moolixir count, which subtracts FJ's current moolixir count by the card's cost.

FJ marks a subset of his cards $s_1, s_2, \ldots, s_k$ as win-conditions ($1\le k\le N$, $1\le s_i\le N$). If FJ has at least one win-condition in his hand, the next card he plays must be a win-condition.

He asks you $Q$ ($1 \leq Q \leq 2 \cdot 10^5$) queries. Each query is of the following form: what is the maximum number of win-conditions he could have placed down within $t$ time ($1 \leq t \leq 10^{18}$)?

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains $N$ and $H$.

The second line contains $N$ integers $a_1, a_2, \ldots, a_N$.

The third line contains an integer $k$, the number of win-conditions.

The fourth line contains $k$ distinct integers $s_1, s_2, \ldots, s_k$.

The fifth line contains an integer $Q$.

The following $Q$ lines each contain an integer $t$, the time to answer for each query.

OUTPUT FORMAT (print output to the terminal / stdout):

For each query, output the maximum number of win-conditions that FJ could've put down within $t$ time.

SAMPLE INPUT:

6 3
2 4 3 5 7 6
2
1 4
6
1
2
3
7
10
1000000000000000

SAMPLE OUTPUT:

0
1
1
2
2
142857142857143

In this case, you start with card 1, a win condition on your hand. You can play it after you accumulate 2 elixir in 2 seconds. This means that just after t=1 you can play no cards, but after t=2 you can play your first card, which must be your win condition.

After t=3, it is still most optimal to play card 1 and have 1 elixir remaining, so the answer here is still 1.

You then draw card 4, which is also a win condition. You play it immediately after t=7, so you have played 2 win conditions at this time.

You then draw card 5 and have no win conditions in your hand. After t=10, even if you play card 3 with the 3 elixir you have, your number of win conditions does not change.

SCORING:

  • Inputs 2-3: $N,Q\le 100$
  • Inputs 4-5: $H=1$
  • Inputs 6-11: No additional constraints.

Problem credits: Chongtian Ma

结果

Kimi K3.1 ProKimi

auto(max)

1/1

解出的采样 ↑

  • 100采样 1 · 解出
  • 54.5k平均输出 token(含思考) ↓
  • 22.9输出速度 tokens/s ↑
  • 2378 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • 无官方解时间复杂度(相对官方解)
  • 5Pylint 问题 ↓
  • 9.24Pylint 得分 ↑
  • 13圈复杂度 ↓
  • 51.2可维护性指数 ↑

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

1/1

解出的采样 ↑

  • 100采样 1 · 解出
  • 49.4k平均输出 token(含思考) ↓
  • 187.0输出速度 tokens/s ↑
  • 264 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • 无官方解时间复杂度(相对官方解)
  • 9Pylint 问题 ↓
  • 8.93Pylint 得分 ↑
  • 14圈复杂度 ↓
  • 49.0可维护性指数 ↑

MiniMax M3.1 FlashMiniMax

auto(max)

0/1

解出的采样 ↑

  • 0.0采样 1 · 答案错误
  • 86.7k平均输出 token(含思考) ↓
  • 108.2输出速度 tokens/s ↑
  • 804 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • —时间复杂度(相对官方解)
  • 7Pylint 问题 ↓
  • 9.12Pylint 得分 ↑
  • 16圈复杂度 ↓
  • 54.9可维护性指数 ↑

↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。

代码

Kimi K3.1 Pro · 采样 1 · 95 行
import sys
from collections import deque
from heapq import heappush, heappop
from bisect import bisect_right


def main():
    it = iter(map(int, sys.stdin.buffer.read().split()))

    n = next(it)
    h = next(it)
    costs = [next(it) for _ in range(n)]

    k = next(it)
    is_win = [False] * (n + 1)
    for _ in range(k):
        is_win[next(it)] = True

    query_count = next(it)
    queries = [next(it) for _ in range(query_count)]
    del it

    queue_size = n - h
    period_length = queue_size + 1

    draw_queue = deque(range(h + 1, n + 1))
    win_hand = []
    other_hand = []

    for card in range(1, h + 1):
        item = (costs[card - 1], card)
        if is_win[card]:
            heappush(win_hand, item)
        else:
            heappush(other_hand, item)

    prefix_cost = [0]
    prefix_wins = [0]
    block_cost = [0]
    block_wins = [0]

    total_cost = 0
    total_wins = 0

    # Playing the cheapest currently legal card is optimal. After the first
    # queue_size plays, at most period_length more plays are needed before
    # the played-card sequence becomes periodic with period period_length.
    for step in range(1, queue_size + period_length + 1):
        if win_hand:
            cost, card = heappop(win_hand)
        else:
            cost, card = heappop(other_hand)

        gained_win = 1 if is_win[card] else 0
        total_cost += cost
        total_wins += gained_win

        drawn = draw_queue.popleft()
        drawn_item = (costs[drawn - 1], drawn)
        if is_win[drawn]:
            heappush(win_hand, drawn_item)
        else:
            heappush(other_hand, drawn_item)
        draw_queue.append(card)

        if step <= queue_size:
            prefix_cost.append(total_cost)
            prefix_wins.append(total_wins)
        else:
            block_cost.append(block_cost[-1] + cost)
            block_wins.append(block_wins[-1] + gained_win)

    base_cost = prefix_cost[-1]
    base_wins = prefix_wins[-1]
    cycle_cost = block_cost[-1]
    cycle_wins = block_wins[-1]

    answers = []
    for limit in queries:
        if limit < base_cost:
            plays = bisect_right(prefix_cost, limit) - 1
            answers.append(prefix_wins[plays])
        else:
            extra = limit - base_cost
            full_cycles, remainder = divmod(extra, cycle_cost)
            offset = bisect_right(block_cost, remainder) - 1
            answers.append(
                base_wins + full_cycles * cycle_wins + block_wins[offset]
            )

    sys.stdout.write("\n".join(map(str, answers)))


if __name__ == "__main__":
    main()