题目 › usaco-1567

Declining Invitations

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

查看原题跳到结果

题面

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

$N$ contestants participated in a contest, each placing a distinct rank from $1$ to $N$. There are $C$ criteria used to invite contestants to participate in the final round, and the $i$th-ranked contestant satisfies a specified $n_i$ of them ($1\le n_i\le C$).

The invitation process runs as follows. First, the top $f_1$ students who satisfy the $1$st criteria will be invited. Then, out of all students who haven't yet been invited, the top $f_2$ (or all remaining if there are fewer than $f_2$ remaining) students who satisfy the $2$nd criterion will be invited. This process repeats, for each $i$ from $1$ to $C$ ($1\le f_i\le N$).

However, some contestants will decline to participate in the final round, in which case they will be ignored when determining who to invite.

You are given a permutation $p_1, p_2, \dots, p_N$ of $1\dots N$. For each $i$ from $0$ to $N-1$, determine the sum of the ranks of the contestants who will be invited if the participants with ranks given by the first $i$ elements of $p$ decline to attend.

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

The first line contains $N$ and $C$ ($1\le N,C\le 10^5$).

The next line contains $f_1,f_2, \dots, f_C$.

The next line contains $p_1, \dots, p_N$.

The next $N$ lines each contain $n_i$ ($1\le n_i\le C$), followed by $n_i$ distinct integers in $[1, C]$, representing the criteria that the $i$th-ranked contestant satisfies. It is guaranteed that $\sum n_i\le 10^6$.

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

Output $N$ lines, the sum of ranks of invitees before each declination.

SAMPLE INPUT:

5 1
3
5 1 3 2 4
1 1
1 1
1 1
1 1
1 1

SAMPLE OUTPUT:

6
6
9
6
4

There is only one criterion. The top three remaining contestants who have not declined will be invited.

SAMPLE INPUT:

5 4
1 1 1 1
1 2 3 4 5
1 1
2 1 2
2 2 3
2 3 4
1 4

SAMPLE OUTPUT:

10
14
12
9
5

Initially, the $i$th contestant gets invited under criterion $i$ for all $1\le i\le 4$.

After the first declination, the $i+1$th contestant gets invited under criterion $i$ for all $1\le i\le 4$.

SAMPLE INPUT:

6 10
5 6 4 1 3 3 3 6 5 3
1 4 6 5 2 3
1 9
5 4 3 9 5 10
10 6 2 10 1 7 8 3 9 4 5
10 4 5 3 1 2 9 10 6 7 8
2 3 1
8 1 9 7 4 3 10 6 2

SAMPLE OUTPUT:

21
20
16
10
5
3

SCORING:

  • Inputs 4-6: $N, C \le 10^3, \sum n_i \le 10^4$
  • Inputs 7-8: $C=1$
  • Inputs 9-10: $C=2$
  • Inputs 11-16: No additional constraints.

Problem credits: Benjamin Qi

结果

Kimi K3.1 ProKimi

auto(max)

1/1

解出的采样 ↑

  • 100采样 1 · 解出
  • 15.0k平均输出 token(含思考) ↓
  • 28.0输出速度 tokens/s ↑
  • 538 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • 无官方解时间复杂度(相对官方解)
  • 6Pylint 问题 ↓
  • 9.23Pylint 得分 ↑
  • 25圈复杂度 ↓
  • 46.8可维护性指数 ↑

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

1/1

解出的采样 ↑

  • 100采样 1 · 解出
  • 27.4k平均输出 token(含思考) ↓
  • 178.1输出速度 tokens/s ↑
  • 155 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • 无官方解时间复杂度(相对官方解)
  • 8Pylint 问题 ↓
  • 8.77Pylint 得分 ↑
  • 18圈复杂度 ↓
  • 48.5可维护性指数 ↑

MiniMax M3.1 FlashMiniMax

auto(max)

1/1

解出的采样 ↑

  • 100采样 1 · 解出
  • 61.7k平均输出 token(含思考) ↓
  • 124.6输出速度 tokens/s ↑
  • 496 秒延迟 ↓
  • —CPU 时间 / 官方解 ↓
  • 无官方解时间复杂度(相对官方解)
  • 7Pylint 问题 ↓
  • 8.94Pylint 得分 ↑
  • 18圈复杂度 ↓
  • 65.7可维护性指数 ↑

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

代码

Kimi K3.1 Pro · 采样 1 · 106 行
import sys


def read_ints():
    data = sys.stdin.buffer.read()
    i = 0
    length = len(data)
    while i < length:
        while i < length and data[i] <= 32:
            i += 1
        if i >= length:
            break
        value = 0
        while i < length and data[i] > 32:
            value = value * 10 + data[i] - 48
            i += 1
        yield value


def main():
    it = read_ints()
    n = next(it)
    c = next(it)

    f = [0] * (c + 1)
    for i in range(1, c + 1):
        f[i] = next(it)

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

    criteria = [[] for _ in range(c + 1)]
    for rank in range(1, n + 1):
        count = next(it)
        for _ in range(count):
            criteria[next(it)].append(rank)
    del it

    # state[r] = 0: uninvited, -1: declined, otherwise invitation criterion.
    state = [0] * (n + 1)
    pointers = [0] * (c + 1)
    answer = 0

    for q in range(1, c + 1):
        contestants = criteria[q]
        index = 0
        chosen = 0
        limit = f[q]
        length = len(contestants)

        while chosen < limit and index < length:
            rank = contestants[index]
            index += 1
            if state[rank] == 0:
                state[rank] = q
                answer += rank
                chosen += 1

        pointers[q] = index

    output = [str(answer)]

    for i in range(n - 1):
        declined = order[i]
        q = state[declined]
        state[declined] = -1

        if q > 0:
            answer -= declined

            # Fill the vacancy. If the replacement was invited at a later
            # criterion, that criterion in turn receives a vacancy.
            while True:
                contestants = criteria[q]
                index = pointers[q]
                length = len(contestants)
                replacement = 0

                while index < length:
                    rank = contestants[index]
                    index += 1
                    old_criterion = state[rank]
                    if old_criterion == 0 or old_criterion > q:
                        replacement = rank
                        break

                pointers[q] = index

                if replacement == 0:
                    break

                old_criterion = state[replacement]
                state[replacement] = q

                if old_criterion == 0:
                    answer += replacement
                    break

                q = old_criterion

        output.append(str(answer))

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


if __name__ == "__main__":
    main()