#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 XX be the string on the screen and YY be the string in the clipboard. Initially, both are empty strings:

  • Operation A: Input a character cc, i.e. update XX to X+cX+c.
  • Operation B: Select all characters and cut, i.e. update YY to XX, and set XX to the empty string.
  • Operation C: Paste the string in the clipboard to the end of the current string, i.e. update XX to X+YX+Y.

For strings or characters x,yx,y, x+yx+y means the result of concatenating xx and yy in order. Performing one operation A, B, C costs A,B,CA,B,C units of time respectively.

You installed the “Useless Editor” and want to input a string SS of length NN as fast as possible.

You need to compute the minimum total time required.

Input Format

The first line contains an integer NN, the length of the string.

The second line contains a string SS of length NN, the string to be typed.

The third line contains an integer AA, the cost of operation A.

The fourth line contains an integer BB, the cost of operation B.

The fifth line contains an integer CC, the cost of operation C.

Output Format

Output one integer in one line, the minimum number of time units required to input the string SS.

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 XX YY Cost Total Time
- "" "" - 00
11 Operation A Input a character "s" 1010
22 Operation B Select all and cut "" "s" 55 1515
33 Operation C Paste at the end "s" 22 1717
44 "ss" 1919
55 Operation A Input a character "ssi" 1010 2929
66 Operation B Select all and cut "" "ssi" 55 3434
77 Operation A Input a character "m" 1010 4444
88 "mi" 5454
99 Operation C Paste at the end "missi" 22 5656
1010 "mississi" 5858
1111 Operation A Input a character "mississip" 1010 6868
1212 "mississipp" 7878
1313 "mississippi" 8888

This sample satisfies the constraints of subtasks 3,4,5,63,4,5,6.

[Sample Explanation #2]

One optimal strategy is as follows:

Round Operation Explanation XX YY Cost Total Time
- "" "" - 00
11 Operation A Input a character "a" 11 11
22 "aa" 22
33 "aaa" 33
44 "aaaa" 44
55 Operation B Select all and cut "" "aaaa" 55
66 Operation C Paste at the end "aaaa" 66
77 "aaaaaaaa" 77
88 "aaaaaaaaaaaa" 88
99 "aaaaaaaaaaaaaaaa" 99

This sample satisfies the constraints of subtasks 2,3,4,5,62,3,4,5,6.

[Sample Explanation #3]

This sample satisfies the constraints of subtasks 3,4,5,63,4,5,6.

[Constraints]

For all testdata, it holds that:

  • 1N25001\leq N\leq 2500.
  • SS is a lowercase letter string of length NN.
  • 1A,B,C1091\leq A,B,C\leq 10^9.

The additional constraints and scores for each subtask are shown in the table below:

Subtask ID Additional Constraints Score
11 N=3N=3 11
22 SS contains only the character a\texttt a 55
33 N30N\le 30 1414
44 N200N\le 200 1010
55 N1000N \le 1000 3232
66 No additional constraints 3838

Translated by ChatGPT 5