시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB69443570.000%

문제

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

  • 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

NN

예제 출력 1

3

SET(N), WRITE, WRITE

예제 입력 2

IOIX

예제 출력 2

7

SET(I), WRITE, NEXT(O), WRITE, WRITE, SET(X), WRITE

예제 입력 3

BABCBACA

예제 출력 3

13

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

W3sicHJvYmxlbV9pZCI6IjMwOTkiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWIzYzRcdWQyYjggXHViOWU0XHVkMmI4XHViOWFkXHVjMmE0IFx1ZDUwNFx1YjliMFx1ZDEzMCIsImRlc2NyaXB0aW9uIjo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190Y29kZSI6IkVuZ2xpc2giLCJzYW1wbGVfZXhwbGFpbl8xIjoiPHA+U0VUKE4pLCBXUklURSwgV1JJVEU8XC9wPlxyXG4iLCJzYW1wbGVfZXhwbGFpbl8yIjoiPHA+U0VUKEkpLCBXUklURSwgTkVYVChPKSwgV1JJVEUsIFdSSVRFLCBTRVQoWCksIFdSSVRFPFwvcD5cclxuIiwic2FtcGxlX2V4cGxhaW5fMyI6IjxwPlNFVChCKSwgV1JJVEUsIE5FWFQoQSksIFdSSVRFLCBXUklURSwgTkVYVChDKSwgV1JJVEUsIFdSSVRFLCBTRVQoQSksIFdSSVRFLCBORVhUKEMpLCBXUklURSwgV1JJVEU8XC9wPlxyXG4ifV0=

출처

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

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