#abc286c. C - Rotate and Palindrome
C - Rotate and Palindrome
Score : points
问题描述
给定一个长度为 的字符串 。令 表示从左数起第 个字符。
你可以按任意顺序执行以下两种操作零次或多次:
-
花费 日元(日本货币)。将 的最左侧字符移动到右侧末尾。换句话说,将 改变为 。
-
花费 日元。选择一个整数 ( 到 之间),并将 替换为任意小写英文字母。
你需要支付多少日元才能使 变成回文串?
什么是回文串?字符串 是回文串当且仅当对于所有整数 (),从左数起第 个字符与从右数起第 个字符相同,其中 表示 的长度。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a string of length . Let be the -th character of from the left.
You may perform the following two kinds of operations zero or more times in any order:
-
Pay yen (the currency in Japan). Move the leftmost character of to the right end. In other words, change to .
-
Pay yen. Choose an integer between and , and replace with any lowercase English letter.
How many yen do you need to pay to make a palindrome?
What is a palindrome? A string is a palindrome if and only if the -th character from the left and the -th character from the right are the same for all integers (), where is the length of .
Constraints
- is a string of length consisting of lowercase English letters.
- All values in the input except for are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
5 1 2
rrefa
Sample Output 1
3
First, pay yen to perform the operation of the second kind once: let to replace with e
. is now rrefe
.
Then, pay yen to perform the operation of the first kind once. is now refer
, which is a palindrome.
Thus, you can make a palindrome for yen. Since you cannot make a palindrome for yen or less, is the answer.
Sample Input 2
8 1000000000 1000000000
bcdfcgaa
Sample Output 2
4000000000
Note that the answer may not fit into a -bit integer type.
update @ 2024/3/10 11:57:22