Logo
(追記) (追記ここまで)

24945번 - Copy and Paste 3 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 2048 MB123443537.634%

문제

JOI, Ltd. is a company known for their “just odd inventions.” Recently, JOI, Ltd. developed a text editor called “Just Odd Editor.”

Using this text editor, we can input a string of characters by performing the following operations several times. Let $X$ be the string displayed on the screen of the text editor. Let $Y$ be the string saved in the clipboard. In the beginning, both of $X$ and $Y$ are the empty string.

  • Operation A : We add one character in the end of the string. Namely, we choose a character $c,ドル and update $X$ to be $X + c$.
  • Operation B : We select all the characters and cut them. Namely, we update $Y$ to be $X$. After that, we set $X$ to be the empty string.
  • Operation C : We paste the string from the clipboard at the end of the string. Namely, we update $X$ to be $X + Y$.

Here, for characters or strings $x,ドル $y,ドル the string $x + y$ means the string obtained by connecting $x$ with $y$ in this order. Performing an operation takes time. If we perform the operation $A,ドル $B,ドル $C$ once, it takes $A,ドル $B,ドル $C$ unit time, respectively.

You installed Just Odd Editor. You want to input a string $S$ of length $N$ as soon as possible. Performing operations, you want to make the string on the display be $S$ as soon as possible.

Write a program which, given the length $N,ドル the string $S,ドル and the amount of unit time needed to perform an operation, calculates the least amount of time needed to input the string $S$.

입력

Read the following data from the standard input.

$\begin{align*} & N \\ & S \\ & A \\ & B \\ & C\end{align*}$

출력

Write one line to the standard output. The output should contain the least amount of time needed to input the string $S$.

제한

  • 1ドル ≤ N ≤ 2,500円$.
  • $S$ is a string of length $N$.
  • Each character of $S$ is a lower-case alphabet ('a' - 'z').
  • 1ドル ≤ A ≤ 1,000円,000円,000円$ ($= 10^9$).
  • 1ドル ≤ B ≤ 1,000円,000円,000円$ ($= 10^9$).
  • 1ドル ≤ C ≤ 1,000円,000円,000円$ ($= 10^9$).
  • $N,ドル $A,ドル $B,ドル $C$ are integers.

서브태스크

번호배점제한
11

$N = 3$.

25

Every character of $S$ is 'a'.

314

$N ≤ 30$.

410

$N ≤ 200$.

532

$N ≤ 1,000円$.

638

No additional constraints.

예제 입력 1

11
mississippi
10
5
2

예제 출력 1

88

By performing the following operations, we can input mississippi by 88ドル$ unit time. Since it is the least amount of time needed to input mississippi, output 88ドル$.

Order Operation Explanation $X$ $Y$ Time Total Time
- - - "" "" - 0ドル$
1 Operation A Add a character in end "s" "" 10ドル$ 10ドル$
2 Operation B Select all & Cut "" "s" 5ドル$ 15ドル$
3 Operation C Paste at end "s" "s" 2ドル$ 17ドル$
4 Operation C Paste at end "ss" "s" 2ドル$ 19ドル$
5 Operation A Add a character in end "ssi" "s" 10ドル$ 29ドル$
6 Operation B Select all & Cut "" "ssi" 5ドル$ 34ドル$
7 Operation A Add a character in end "m" "ssi" 10ドル$ 44ドル$
8 Operation A Add a character in end "mi" "ssi" 10ドル$ 54ドル$
9 Operation C Paste at end "missi" "ssi" 2ドル$ 56ドル$
10 Operation C Paste at end "mississi" "ssi" 2ドル$ 58ドル$
11 Operation A Add a character in end "mississip" "ssi" 10ドル$ 68ドル$
12 Operation A Add a character in end "mississipp" "ssi" 10ドル$ 78ドル$
13 Operation A Add a character in end "mississippi" "ssi" 10ドル$ 88ドル$

This sample input satisfies the constraints of Subtasks 3, 4, 5, 6.

예제 입력 2

16
aaaaaaaaaaaaaaaa
1
1
1

예제 출력 2

9

By performing the following operations, we can input aaaaaaaaaaaaaaaa by 9ドル$ unit time. Since it is the least amount of time needed to input aaaaaaaaaaaaaaaa, output 9ドル$.

Order Operation Explanation $X$ $Y$ Time Total Time
- - - "" "" - 0ドル$
1 Operation A Add a character in end "a" "" 1ドル$ 1ドル$
2 Operation A Add a character in end "aa" "" 1ドル$ 2ドル$
3 Operation A Add a character in end "aaa" "" 1ドル$ 3ドル$
4 Operation A Add a character in end "aaaa" "" 1ドル$ 4ドル$
5 Operation B Select all & Cut "" "aaaa" 1ドル$ 5ドル$
6 Operation C Paste at end "aaaa" "aaaa" 1ドル$ 6ドル$
7 Operation C Paste at end "aaaaaaaa" "aaaa" 1ドル$ 7ドル$
8 Operation C Paste at end "aaaaaaaaaaaa" "aaaa" 1ドル$ 8ドル$
9 Operation C Paste at end "aaaaaaaaaaaaaaaa" "aaaa" 1ドル$ 9ドル$

This sample input satisfies the constraints of Subtasks 2, 3, 4, 5, 6.

예제 입력 3

18
aababbbababbbaabbb
1000000000
100000
10000000

예제 출력 3

8060200000

This sample input satisfies the constraints of Subtasks 3, 4, 5, 6.

힌트

출처

Camp > JOI Spring Training Camp > JOI 2021/2022 Spring Training Camp 2-1번

Camp > JOIG Spring Training Camp > JOIG 2021/2022 Spring Training Camp 1-4번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /