아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Journals

시간 제한1초메모리 제한1024 MB

요약
플러스 K개와 마이너스 K개로 이루어진 문자열이 주어질 때, 부호가 번갈아 나오도록 만드는 데 필요한 최소 블록 이동 횟수를 구한다.
난이도

보통10점 중 4점

유형
문자열, 그리디, 구현
정답자
아직 제출이 없습니다

문제

There is a stack of journals on Cimrman’s desk. The journals are printed in Cimrman’s own printing house. Each journal front cover is charged slightly positively and the back cover is charged slightly negatively. Different charges of the front and back cover help the journals to stick better to each other when they are stacked in a single stack one upon another. When two adjacent journals in the stack are positioned in such a way that either their front covers or their back covers touch each other, the repulsion between the same charges in both covers makes the stack more prone to collapse.

Cimrman wants his stack to be arranged in such a way that no two adjacent journals in the stack produce the repulsion.

To set the stack into appropriate order he can repeat a single operation consisting of three moves. In the first move (which may be empty), Cimrman puts aside some number of journals from the top of the stack without changing their order. Next, he takes a pile of one or more journals from the new top of the stack, flips this pile over, and puts it back on the stack. Finally, he moves back onto the stack the journals removed from the stack in the first step. Again, no change of the journal order appears in this move.

Obviously, Cimrman wants to perform as few operations as possible. The number of journals moved or flipped in one operation is not important, the journals paper is light enough.

입력

The journals’ front and back covers are represented by signs plus or minus (’+’ or ’-’) in the input. The single line of input contains K (1 ≤ K ≤ 105) plus signs and K minus signs without spaces between them. The input corresponds to the original orientation of the journals on the stack.

출력

Print the minimal number of operations to be performed to achieve a stack where no two adjacent journals produce the repulsion.

예제2

  1. 예제 1

    입력
    +-+-+--+-+
    
    예상 출력
    1
    
  2. 예제 2

    입력
    +--++-
    
    예상 출력
    1