Logo
(追記) (追記ここまで)

16420번 - Paper Strips 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB225538.462%

문제

Tito has been given a paper strip with a string of letters written on it. He would like to rearrange the letters. He does this by making some number of cuts between letters and then rearranging the strips of paper.

Tito likes order, so he would like the resulting strip of paper to be bitonic. That is, there should be some character position in the resulting string where the characters up to and including that position are alphabetically non-decreasing and all characters after and including that position are alphabetically non-increasing. Consider this example:

The resulting string in the above example is bitonic. Consider the first e. The string aaabbe is non-decreasing, and the string eeddcc is non-increasing. Tito achieved this with three cuts. Note that any string which is monotonic (uniformly nondecreasing or nonincreasing) is also bitonic.

Determine the minimum number of cuts that Tito needs in order to make his string bitonic.

입력

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs.

Each test case will consist of a single line containing a string s (1 ≤ |s| ≤ 50) which consists only of lower-case letters. This is the original string on the strip of paper given to Tito.

출력

Output a single integer, which is the minimum number of required cuts.

제한

예제 입력 1

abbaaddccee

예제 출력 1

3

힌트

출처

ICPC > Regionals > North America > Southeast USA Regional > 2018 Southeast USA Regional Programming Contest > Division 1 H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /