#P16303. [蓝桥杯 2026 省 Java C 组] 小蓝的序列
[蓝桥杯 2026 省 Java C 组] 小蓝的序列
Problem Description
Xiaolan believes that a sequence is “good” if and only if it satisfies the following conditions:
- Exactly two different integers appear in the sequence.
- Any pair of adjacent elements are different.
- For all valid indices (), we have .
Equivalently, a good sequence must look like
or
where , and only these two numbers appear in the entire sequence.
Now Xiaolan has a sequence of length . He can perform any number of modification operations. In each operation, he can change one element in the sequence to any positive integer.
Xiaolan wants to know: what is the minimum number of elements that must be modified to turn the current sequence into a good sequence?
Input Format
The input consists of two lines.
The first line contains a positive integer , representing the length of the sequence.
The second line contains positive integers , representing Xiaolan's current sequence.
Output Format
Output one line containing a non-negative integer , representing the minimum number of elements that must be modified to make the sequence a good sequence.
5
1 1 1 1 2
2
Hint
Sample Explanation
One optimal plan is to change the st and the rd numbers to . Then the sequence becomes:
This is a good sequence. It can be verified that there is no way to satisfy the conditions by modifying only element, so the answer is .
Constraints
- For of the testdata, .
- Another of the testdata satisfy: for all , we have .
- For all testdata, , and .
Translated by ChatGPT 5