题面
来源:USACO 官网。模型收到的是同一份题面的文字。
Farmer John is trying to describe his favorite USACO contest to Elsie, but she is having trouble understanding why he likes it so much. He says "My favorite part of the contest was when Bessie said 'It's Mooin' Time' and mooed all over the contest."
Elsie still doesn't understand, so Farmer John downloads the contest as a text file and tries to explain what he means. The contest is defined as an array of $N$ ($1\le N\le 10^6$) integers $a_1, a_2, \dots, a_N$ ($1\le a_i\le N$). Farmer John defines a moo as an array of three integers where the second integer equals the third but not the first. A moo is said to occur in the contest if it is possible to remove integers from the array until only the moo remains.
As Bessie allegedly "mooed all over the contest", help Elsie count the number of distinct moos that occur in the contest! Two moos are distinct if they do not consist of the same integers in the same order.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains $N$.The second line contains $N$ space-separated integers $a_1,a_2,\dots,a_N$.
OUTPUT FORMAT (print output to the terminal / stdout):
Output the number of distinct moos that occur in the contest.**Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long" in Java, a "long long" in C/C++).**
SAMPLE INPUT:
6 1 2 3 4 4 4
SAMPLE OUTPUT:
3
This contest has three distinct moos: "1 4 4", "2 4 4", and "3 4 4".
SCORING:
- Inputs 2-4: $N\le 10^2$
- Inputs 5-7: $N\le 10^4$
- Inputs 8-11: No additional constraints.
Problem credits: Benjamin Qi
结果
Kimi K3.1 ProKimi
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 5.0k平均输出 token(含思考) ↓
- 28.6输出速度 tokens/s ↑
- 177 秒延迟 ↓
- 0.50×CPU 时间 / 官方解 ↓
- 同阶时间复杂度(相对官方解)
- 2Pylint 问题 ↓
- 9.05Pylint 得分 ↑
- 5圈复杂度 ↓
- 72.9可维护性指数 ↑
DeepSeek Flash V4.1-1017DeepSeek
1/1
解出的采样 ↑
- 100采样 1 · 解出
- 8.2k平均输出 token(含思考) ↓
- 203.7输出速度 tokens/s ↑
- 41 秒延迟 ↓
- 0.55×CPU 时间 / 官方解 ↓
- 同阶时间复杂度(相对官方解)
- 3Pylint 问题 ↓
- 8.97Pylint 得分 ↑
- 7圈复杂度 ↓
- 51.2可维护性指数 ↑
MiniMax M3.1 FlashMiniMax
0/1
解出的采样 ↑
- 9.1采样 1 · 答案错误
- 2.7k平均输出 token(含思考) ↓
- 169.5输出速度 tokens/s ↑
- 17 秒延迟 ↓
- —CPU 时间 / 官方解 ↓
- —时间复杂度(相对官方解)
- 2Pylint 问题 ↓
- 8.82Pylint 得分 ↑
- 4圈复杂度 ↓
- 81.6可维护性指数 ↑
↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
import sys def main(): data = sys.stdin.buffer.read().split() n = int(data[0]) a = list(map(int, data[1:])) del data remaining = [0] * (n + 1) for x in a: remaining[x] += 1 seen = bytearray(n + 1) distinct = 0 answer = 0 for x in a: # This is the penultimate occurrence of x. Every different value # before it can form a moo whose last two values are x. if remaining[x] == 2: answer += distinct - seen[x] if not seen[x]: seen[x] = 1 distinct += 1 remaining[x] -= 1 sys.stdout.write(str(answer)) main()
import sys from array import array def main(): data = sys.stdin.buffer.read().split() if not data: return N = int(data[0]) total = array('I', [0]) * (N + 1) a = array('I', [0]) * N for i in range(N): v = int(data[i + 1]) a[i] = v total[v] += 1 del data present = bytearray(N + 1) ans = 0 distinct = 0 for v in a: if total[v] == 2: ans += distinct if present[v]: ans -= 1 if present[v] == 0: present[v] = 1 distinct += 1 total[v] -= 1 sys.stdout.write(str(ans)) if __name__ == "__main__": main()
import sys def solve(): values = map(int, sys.stdin.buffer.read().split()) n = next(values) # 0: unseen, 1: seen once, 2: seen at least twice state = bytearray(n + 1) distinct_seen = 0 answer = 0 for value in values: if state[value] == 0: state[value] = 1 distinct_seen += 1 elif state[value] == 1: # Every previously seen distinct value except this one # can form a moo (x, value, value). answer += distinct_seen - 1 state[value] = 2 print(answer) if __name__ == "__main__": solve()