#P9523. Useless Editor Typing
Useless Editor Typing
Useless Editor Typing
JOI Corporation, famous for its "useless inventions," has developed a new text editor called the "Useless Editor." In this editor, you can perform the following operations to input a string. Let (X) denote the current string on the screen, and (Y) denote the string in the clipboard; both are initially empty.
- Operation A: Input a character \(c\). This updates \(X\) to \(X+c\). This operation costs \(A\) time units.
- Operation B: Select all characters and cut them. This sets \(Y = X\) and resets \(X\) to the empty string. This operation costs \(B\) time units.
- Operation C: Paste the clipboard string to the end of the current string. This updates \(X\) to \(X+Y\). This operation costs \(C\) time units.
For any strings (or characters) (x) and (y), the notation (x+y) means the concatenation of (x) and (y) in that order.
You are given three positive integers (A, B, C) representing the time costs of operations A, B, and C respectively, and a target string (S) of length (N) (where (N = |S|)). Your task is to determine the minimum time required to produce the string (S) using the Useless Editor.
Note: When you perform Operation B, the current screen content is cleared. Therefore, if you use the copy-paste method, the final string must be composed entirely of copies of a non‐empty substring (T) (i.e. (S = TTT\cdots T)). In that case, the strategy is to type (T) manually using Operation A, then perform Operation B once to copy (T) (losing the typed (T)), and finally use Operation C repeatedly to paste copies of (T) to form (S). The total cost for this strategy is (|T|\cdot A + B + m\cdot C) if (S) consists of (m) copies of (T) (with (m \ge 2)). Alternatively, you can choose to type every character using Operation A, with a cost of (|S|\cdot A).
Your goal is to output the minimum possible time to produce (S).
inputFormat
The input consists of two lines:
- The first line contains three space-separated positive integers \(A, B, C\) (\(1 \le A,B,C \le 10^9\)).
- The second line contains the target string \(S\), consisting of only lowercase English letters. Its length \(N\) satisfies \(1 \le N \le 10^5\).
outputFormat
Output a single integer: the minimum time required to produce the string \(S\) using the available operations.
sample
1 1 1
aa
2