#P9523. [JOIST 2022] 复制粘贴 3 / Copy and Paste 3
[JOIST 2022] 复制粘贴 3 / Copy and Paste 3
Background
JOISC2022 D2T1
Problem Description
JOI Company is a company famous for “useless inventions”. Recently, JOI Company developed an editor called the “Useless Editor”.
In this editor, you can perform the following operations to input a string. Let be the string on the screen and be the string in the clipboard. Initially, both are empty strings:
- Operation A: Input a character , i.e. update to .
- Operation B: Select all characters and cut, i.e. update to , and set to the empty string.
- Operation C: Paste the string in the clipboard to the end of the current string, i.e. update to .
For strings or characters , means the result of concatenating and in order. Performing one operation A, B, C costs units of time respectively.
You installed the “Useless Editor” and want to input a string of length as fast as possible.
You need to compute the minimum total time required.
Input Format
The first line contains an integer , the length of the string.
The second line contains a string of length , the string to be typed.
The third line contains an integer , the cost of operation A.
The fourth line contains an integer , the cost of operation B.
The fifth line contains an integer , the cost of operation C.
Output Format
Output one integer in one line, the minimum number of time units required to input the string .
11
mississippi
10
5
2
88
16
aaaaaaaaaaaaaaaa
1
1
1
9
18
aababbbababbbaabbb
1000000000
100000
10000000
8060200000
Hint
[Sample Explanation #1]
One optimal sequence of operations is as follows:
| Round | Operation | Explanation | Cost | Total Time | ||
|---|---|---|---|---|---|---|
| - | "" |
"" |
- | |||
| Operation A | Input a character | "s" |
||||
| Operation B | Select all and cut | "" |
"s" |
|||
| Operation C | Paste at the end | "s" |
||||
"ss" |
||||||
| Operation A | Input a character | "ssi" |
||||
| Operation B | Select all and cut | "" |
"ssi" |
|||
| Operation A | Input a character | "m" |
||||
"mi" |
||||||
| Operation C | Paste at the end | "missi" |
||||
"mississi" |
||||||
| Operation A | Input a character | "mississip" |
||||
"mississipp" |
||||||
"mississippi" |
||||||
This sample satisfies the constraints of subtasks .
[Sample Explanation #2]
One optimal strategy is as follows:
| Round | Operation | Explanation | Cost | Total Time | ||
|---|---|---|---|---|---|---|
| - | "" |
"" |
- | |||
| Operation A | Input a character | "a" |
||||
"aa" |
||||||
"aaa" |
||||||
"aaaa" |
||||||
| Operation B | Select all and cut | "" |
"aaaa" |
|||
| Operation C | Paste at the end | "aaaa" |
||||
"aaaaaaaa" |
||||||
"aaaaaaaaaaaa" |
||||||
"aaaaaaaaaaaaaaaa" |
||||||
This sample satisfies the constraints of subtasks .
[Sample Explanation #3]
This sample satisfies the constraints of subtasks .
[Constraints]
For all testdata, it holds that:
- .
- is a lowercase letter string of length .
- .
The additional constraints and scores for each subtask are shown in the table below:
| Subtask ID | Additional Constraints | Score |
|---|---|---|
| contains only the character | ||
| No additional constraints |
Translated by ChatGPT 5