题面
来源:USACO 官网。模型收到的是同一份题面的文字。
You are given an array $a$ of $N$ non-negative integers $a_1, a_2, \dots, a_N$ ($1\le N\le 2\cdot 10^5, 0\le a_i\le N$). In one operation, you can change any element of $a$ to any non-negative integer.
The mex of an array is the minimum non-negative integer that it does not contain. For each $i$ in the range $0$ to $N$ inclusive, compute the minimum number of operations you need in order to make the mex of $a$ equal $i$.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains $N$.The next line contains $a_1,a_2,\dots, a_N$.
OUTPUT FORMAT (print output to the terminal / stdout):
For each $i$ in the range $0$ to $N$, output the minimum number of operations for $i$ on a new line. Note that it is always possible to make the mex of $a$ equal to any $i$ in the range $0$ to $N$.SAMPLE INPUT:
4 2 2 2 0
SAMPLE OUTPUT:
1 0 3 1 2
- To make the mex of $a$ equal to $0$, we can change $a_4$ to $3$ (or any positive integer). In the resulting array, $[2, 2, 2, 3]$, $0$ is the smallest non-negative integer that the array does not contain, so $0$ is the mex of the array.
- To make the mex of $a$ equal to $1$, we don't need to make any changes since $1$ is already the smallest non-negative integer that $a = [2, 2, 2, 0]$ does not contain.
- To make the mex of $a$ equal to $2$, we need to change the first three elements of $a$. For example, we can change $a$ to be $[3, 1, 1, 0]$.
SCORING:
- Inputs 2-6: $N\le 10^3$
- Inputs 7-11: No additional constraints.
Problem credits: Benjamin Qi
结果
Kimi K3.1 ProKimi
auto(max)
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 3.1k平均输出 token(含思考) ↓
- 31.3输出速度 tokens/s ↑
- 101 秒延迟 ↓
- 0.63×CPU 时间 / 官方解 ↓
- 同阶时间复杂度(相对官方解)
- 2Pylint 问题 ↓
- 8.82Pylint 得分 ↑
- 4圈复杂度 ↓
- 58.7可维护性指数 ↑
DeepSeek Flash V4.1-1017DeepSeek
auto(high)
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 3.0k平均输出 token(含思考) ↓
- 199.1输出速度 tokens/s ↑
- 16 秒延迟 ↓
- 0.57×CPU 时间 / 官方解 ↓
- 同阶时间复杂度(相对官方解)
- 2Pylint 问题 ↓
- 8.95Pylint 得分 ↑
- 5圈复杂度 ↓
- 56.7可维护性指数 ↑
MiniMax M3.1 FlashMiniMax
auto(max)
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 5.2k平均输出 token(含思考) ↓
- 424.4输出速度 tokens/s ↑
- 13 秒延迟 ↓
- 0.45×CPU 时间 / 官方解 ↓
- 同阶时间复杂度(相对官方解)
- 2Pylint 问题 ↓
- 8.82Pylint 得分 ↑
- 5圈复杂度 ↓
- 76.8可维护性指数 ↑
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
Kimi K3.1 Pro · 采样 1 · 23 行
import sys def main(): data = list(map(int, sys.stdin.buffer.read().split())) n = data[0] a = data[1:] count = [0] * (n + 1) for x in a: count[x] += 1 missing = 0 answers = [] for i in range(n + 1): answers.append(str(max(count[i], missing))) if count[i] == 0: missing += 1 sys.stdout.write("\n".join(answers)) if __name__ == "__main__": main()
DeepSeek Flash V4.1-1017 · 采样 1 · 27 行
import sys def solve(): data = list(map(int, sys.stdin.buffer.read().split())) if not data: return n = data[0] a = data[1:1 + n] count = [0] * (n + 2) for x in a: count[x] += 1 missing = 0 ans = [] for mex in range(n + 1): ans.append(str(max(count[mex], missing))) if count[mex] == 0: missing += 1 sys.stdout.write("\n".join(ans)) if __name__ == "__main__": solve()
MiniMax M3.1 Flash · 采样 1 · 25 行
import sys def solve(): data = list(map(int, sys.stdin.buffer.read().split())) n = data[0] freq = [0] * (n + 2) for v in data[1:1 + n]: freq[v] += 1 out = [] missing = 0 # number of absent values among 0..i-1 for i in range(n + 1): c = freq[i] out.append(str(c if c > missing else missing)) if c == 0: missing += 1 # value i is absent, so it counts as missing for i+1 sys.stdout.write("\n".join(out) + "\n") if __name__ == "__main__": solve()