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

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

Jesting Jabberwocky

면접 대비

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

요약
네 가지 무늬 문자로 이루어진 문자열이 주어질 때, 각 무늬가 연속하도록 카드를 옮기는 최소 횟수를 구한다.
난이도

보통10점 중 5점

유형
동적 계획법, 문자열, 완전 탐색, 구현
정답자
아직 제출이 없습니다

문제

Figure J.1: In Sample 1, Alice has to move at least two cards to sort her hand.

The famous card game manufacturer Greatest Cards Production Company (GCPC) has just created the brand new card game Jabberwocky. In this game, everyone gets the same amount of cards -- which might be quite a lot -- and each card belongs to one of four different suits: hearts, diamonds, clubs, or spades.

As huge card game nerds, Alice and her friends are very hyped about meeting up and trying out the card game everybody seems to talk about these days. Due to a traffic jam, Alice is a bit late to the party and her friends are impatiently waiting for her. They have already distributed all cards and everybody is ready to go, except for Alice. She has just picked up her cards and insists on sorting them by suit first. For that, she repeatedly picks one card from her hand and inserts it somewhere else until her cards are grouped by suit. Her friends are getting increasingly annoyed with Alice and she wants to sort her cards as quickly as possible. How many cards does Alice need to move before they can start playing?

입력

The input consists of:

  • One line with a string ss (1≤∣s∣≤1051\leq|s|\leq 10^5), representing the suits of Alice's cards as they are initially ordered. The string consists of the characters h, d, c, and s (hearts, diamonds, clubs and spades).

출력

Output a single integer, the minimum number of cards Alice has to move in order to sort the cards by suit.

예제2

  1. 예제 1

    입력
    hccdhcd
    
    예상 출력
    2
    
  2. 예제 2

    입력
    cchhdshcdshdcsh
    
    예상 출력
    7