시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 128 MB152063146940.997%

문제

오른쪽 그림과 같은 핸드폰 자판이 있다. 이 자판을 이용하여 어떤 영어 메시지를 치려고 할 때, 걸리는 최소 시간을 구하는 프로그램을 작성하시오.

단, 1번은 누를 경우에는 공백이 찍힌다고 하자. 그리고 만약에 AC라는 문자를 치려 한다면 A를 치고 난 후 일정 시간을 기다린 후 C를 치면 된다.

하나의 문자를 입력하려면, 버튼을 눌러야 한다. 버튼을 누르면 버튼에 쓰여 있는 문자가 입력되며, 버튼을 누를 때 마다 다음 문자로 바뀌게 된다. 예를 들어, 2를 누르면 A, 2번 누르면 B, 3번 누르면 C이다. 공백을 연속으로 누를 때는 기다릴 필요가 없다.

입력

첫째 줄에 p와 w가 주어진다. (1 ≤ p, w ≤ 1,000) p는 버튼을 한번 누르는데 걸리는 시간이고, w는 AC와 같은, 같은 숫자인 문자를 연속으로 찍기 위해 기다리는 시간을 의미한다. 그리고 둘째 줄에는 적을 문자열이 주어진다. 단, 이 문자열의 길이는 1000보다 작고, 맨 앞과 맨 뒤에 공백이 들어오는 경우는 없다. 문자열은 알파벳 대문자와 띄어쓰기만으로 이루어져 있다.

출력

첫째 줄에 메시지를 적는데 걸리는 시간을 출력한다.

예제 입력 1

2 10
ABBAS SALAM

예제 출력 1

72
W3sicHJvYmxlbV9pZCI6IjIwMzciLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJiMzhcdWM3OTBcdWJhNTRcdWMyZGNcdWM5YzAiLCJkZXNjcmlwdGlvbiI6IjxwPjxpbWcgYWx0PVwiXCIgc3JjPVwiaHR0cHM6XC9cL29ubGluZWp1ZGdlaW1hZ2VzLnMzLWFwLW5vcnRoZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VwbG9hZFwvMjAxMDA3XC9zbXMucG5nXCIgc3R5bGU9XCJoZWlnaHQ6IDE3NHB4OyB3aWR0aDogMTM3cHg7IGZsb2F0OiByaWdodDtcIiBcLz5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zLiBUaGVyZSBpcyBubyBsZWFkaW5nIG9yIHRyYWlsaW5nIHNwYWNlcyBpbiBhIGxpbmUuPFwvcD5cclxuIiwib3V0cHV0IjoiPHA+T3V0cHV0IG9uZSBsaW5lIHNob3dpbmcgdGhlIHRpbWUgbmVlZGVkIHRvIHR5cGUgdGhlIG1lc3NhZ2UgaW4gbWlsbGlzZWNvbmRzLjxcL3A+XHJcbiIsImhpbnQiOiIiLCJvcmlnaW5hbCI6IjEiLCJodG1sX3RpdGxlIjoiMCIsInByb2JsZW1fbGFuZ190Y29kZSI6IkVuZ2xpc2gifV0=

출처

ICPC > Regionals > Asia West Continent > Iran > Tehran Site 2005 B번

  • 잘못된 데이터를 찾은 사람: djm03178
  • 빠진 조건을 찾은 사람: djm03178