#abc286c. C - Rotate and Palindrome

C - Rotate and Palindrome

Score : 300300 points

问题描述

给定一个长度为 NN 的字符串 SS。令 Si (1iN)S_i\ (1\leq i \leq N) 表示从左数起第 ii 个字符。

你可以按任意顺序执行以下两种操作零次或多次:

  • 花费 AA 日元(日本货币)。将 SS 的最左侧字符移动到右侧末尾。换句话说,将 S1S2SNS_1S_2\ldots S_N 改变为 S2SNS1S_2\ldots S_NS_1

  • 花费 BB 日元。选择一个整数 ii11NN 之间),并将 SiS_i 替换为任意小写英文字母。

你需要支付多少日元才能使 SS 变成回文串?

什么是回文串?字符串 TT 是回文串当且仅当对于所有整数 ii1iT1 \le i \le |T|),从左数起第 ii 个字符与从右数起第 ii 个字符相同,其中 T|T| 表示 TT 的长度。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a string SS of length NN. Let Si (1iN)S_i\ (1\leq i \leq N) be the ii-th character of SS from the left.

You may perform the following two kinds of operations zero or more times in any order:

  • Pay AA yen (the currency in Japan). Move the leftmost character of SS to the right end. In other words, change S1S2SNS_1S_2\ldots S_N to S2SNS1S_2\ldots S_NS_1.

  • Pay BB yen. Choose an integer ii between 11 and NN, and replace SiS_i with any lowercase English letter.

How many yen do you need to pay to make SS a palindrome?

What is a palindrome? A string TT is a palindrome if and only if the ii-th character from the left and the ii-th character from the right are the same for all integers ii (1iT1 \le i \le |T|), where T|T| is the length of TT.

Constraints

  • 1N50001\leq N \leq 5000
  • 1A,B1091\leq A,B\leq 10^9
  • SS is a string of length NN consisting of lowercase English letters.
  • All values in the input except for SS are integers.

Input

The input is given from Standard Input in the following format:

NN AA BB

SS

Output

Print the answer as an integer.

Sample Input 1

5 1 2
rrefa

Sample Output 1

3

First, pay 22 yen to perform the operation of the second kind once: let i=5i=5 to replace S5S_5 with e. SS is now rrefe.

Then, pay 11 yen to perform the operation of the first kind once. SS is now refer, which is a palindrome.

Thus, you can make SS a palindrome for 33 yen. Since you cannot make SS a palindrome for 22 yen or less, 33 is the answer.

Sample Input 2

8 1000000000 1000000000
bcdfcgaa

Sample Output 2

4000000000

Note that the answer may not fit into a 3232-bit integer type.

update @ 2024/3/10 11:57:22