시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 26 16 12 85.714%

문제

종수는 아두이노 프로젝트에 사용할 도트 매트릭스 프린터를 하나 구매했다. 오랜 시간동안 아두이노와 프린터 사이의 통신을 연구하고 구현한 결과 프린터에 세 가지 명령을 내릴 수 있게 되었다.

  • SET(X): 프린터의 주 메모리에 글자 X를 저장한다.
  • NEXT(X): 프린터의 보조 메모리에 글자 X를 저장한다.
  • WRITE: 주 메모리에 저장되어 있는 글자를 인쇄한다. 바로 이전에 사용한 명령이 NEXT인 경우에는 보조 메모리에 저장된 글자를 출력한다.

예를 들어, "AABAA"를 출력하려면 아래와 같은 명령 8개를 입력하면 된다.

SET(A), WRITE, WRITE, SET(B), WRITE, SET(A), WRITE, WRITE. 

NEXT를 사용하면 7개로 인쇄할 수 있다.

SET(A), WRITE, WRITE, NEXT(B), WRITE, WRITE, WRITE. 

알파벳 대문자로만 이루어진 단어가 주어졌을 때, 이 단어를 출력하는데 필요한 명령 개수의 최솟값을 구하는 프로그램을 작성하시오.

첫 번째 명령은 반드시 SET이어야 한다.

입력

첫째 줄에 인쇄해야하는 단어가 주어진다. 단어는 알파벳 대문자로만 이루어져 있으며, 길이는 10,000을 넘지 않는다. 

출력

입력으로 주어진 단어를 출력하는데 필요한 명령 개수의 최솟값을 출력한다.

예제 입력 1

BABCBACA

예제 출력 1

13

힌트

SET(B), WRITE, NEXT(A), WRITE, WRITE, NEXT(C), WRITE, WRITE, SET(A), WRITE, NEXT(C), WRITE, WRITE. 

W3sicHJvYmxlbV9pZCI6IjMwOTkiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWIzYzRcdWQyYjggXHViOWU0XHVkMmI4XHViOWFkXHVjMmE0IFx1ZDUwNFx1YjliMFx1ZDEzMCIsImRlc2NyaXB0aW9uIjoiPHA+XHVjODg1XHVjMjE4XHViMjk0IFx1YzU0NFx1YjQ1MFx1Yzc3NFx1YjE3OCBcdWQ1MDRcdWI4NWN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ZS4mbmJzcDs8XC9wPlxyXG5cclxuPHA+PHN0cm9uZz5Ob3RlPFwvc3Ryb25nPjogRmlyc3QgY29tbWFuZCBoYXMgdG8gYmUgU0VULiZuYnNwOzxcL3A+XHJcbiIsImlucHV0IjoiPHA+VGhlIGZpcnN0IGxpbmUgY29udGFpbnMgdGhlIHNlcXVlbmNlIG9mIGNoYXJhY3RlcnMgdG8gYmUgcHJpbnRlZC4gVGhlIHNlcXVlbmNlIGNvbnRhaW5zIHVwcGVyIGNhc2UgZW5nbGlzaCBsZXR0ZXJzIGFuZCBpcyBub3QgbG9uZ2VyIHRoYW4gMTAgMDAwLiZuYnNwOzxcL3A+XHJcbiIsIm91dHB1dCI6IjxwPk91dHB1dCBvbmUgaW50ZWdlciwgdGhlIG1pbmltdW0gbnVtYmVyIG9mIGNvbW1hbmRzIG5lZWRlZCB0byBwcmludCB0aGUgc2VxdWVuY2UuJm5ic3A7PFwvcD5cclxuXHJcbjxwPiZuYnNwOzxcL3A+XHJcbiIsImhpbnQiOiI8cD5TRVQoQiksIFdSSVRFLCBORVhUKEEpLCBXUklURSwgV1JJVEUsIE5FWFQoQyksIFdSSVRFLCBXUklURSwgU0VUKEEpLCBXUklURSwgTkVYVChDKSwgV1JJVEUsIFdSSVRFLiZuYnNwOzxcL3A+XHJcbiIsIm9yaWdpbmFsIjoiMSIsInByb2JsZW1fbGFuZ19jb2RlIjoiXHVjNjAxXHVjNWI0In1d

출처

Olympiad > Croatian Highschool Competitions in Informatics > 2010 > School Competition - Juniors 3번

  • 문제를 번역한 사람: baekjoon
  • 문제의 오타를 찾은 사람: jh05013