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

21615번 - Arranging Books 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB88473856.716%

문제

Valentina wants books on a shelf to be arranged in a particular way. Every time she sees a shelf of books, she rearranges the books so that all the large books appear on the left, followed by all the medium-sized books, and then all the small books on the right. She does this by repeatedly choosing any two books and exchanging their locations. Exchanging the locations of two books is called a swap.

Help Valentina determine the fewest number of swaps needed to arrange a shelf of books as she wishes.

입력

The input will consist of exactly one line containing at most 500 000 characters. Each character will be L, M, or S.

출력

Output a single integer which is equal to the minimum possible number of swaps needed to arrange the books so that all occurrences of L come first, followed by all occurrences of M, and then all occurrences of S.

제한

예제 입력 1

LMMMS

예제 출력 1

0

The books are already arranged according to Valentina’s wishes.

예제 입력 2

LLSLM

예제 출력 2

2

By swapping the S and M, we end up with LLMLS. Then the M can be swapped with the L to its right. This is one way to use two swaps to arrange the books as Valentina wants them to be. It is not possible to use fewer swaps because both S and M need to be moved but using one swap to exchange them does not leave the books arranged as Valentina wants them to be.

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2021 > CCC 2021 Junior Division 4번

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

출처

대학교 대회

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

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