#abc206d. D - KAIBUNsyo
D - KAIBUNsyo
Score : points
问题陈述
给定一个包含 个正整数的序列:。你可以执行零次或多次以下操作。至少需要多少次操作才能使 变为回文序列?
- 选择一对正整数 ,并在 中用 替换所有出现的 。
这里我们说 是回文序列,当且仅当对于每个 (),满足 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a sequence of positive integers: . You can do the operation below zero or more times. At least how many operations are needed to make a palindrome?
- Choose a pair of positive integers, and replace every occurrence of in with .
Here, we say is a palindrome if and only if holds for every ().
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
8
1 5 3 2 5 2 3 1
Sample Output 1
2
- Initially, we have .
- After replacing every occurrence of in with , we have .
- After replacing every occurrence of in with , we have .
In this way, we can make a palindrome in two operations, which is the minimum needed.
Sample Input 2
7
1 2 3 4 1 2 3
Sample Output 2
1
Sample Input 3
1
200000
Sample Output 3
0
may already be a palindrome in the beginning.
update @ 2024/3/10 09:19:31