포럼
문제 ICPC00315

G. Game Night

설명

-3mm

-15mm

It is finally Bobby's birthday, and all of his Acquaintances, Buddies and Colleagues have gathered for a board game night. They are going to play a board game which is played in up to three big teams. Bobby decided to split his guests into how well he knows them: the Acquaintances on team \(A\), the Buddies on team \(B\), and the Colleagues on team \(C\).

While Bobby was busy explaining the rules to everyone, all his guests already took seats around his large, circular living room table. However, for the game it is crucial that all people sitting on a team are sitting next to each other. Otherwise, members of other teams could easily eavesdrop on their planning, ruining the game. So some people may need to change seats to avoid this from happening.

Bobby wants to start playing the game as soon as possible, so he wants people to switch seats as efficiently as possible. Given the current arrangement around the circular table, can you figure out the minimal number of people that must switch seats so that the teams are lined up correctly?

제약
입력 형식
  • The first line of the input contains the integer \(n\), where $1 \leq n \leq
    10^5$ is the number of players (as well as seats).
  • The second line contains a string of length \(n\), consisting only of the characters in ABC. This indicates the teams of the people sitting around the table in order.
출력 형식

Print a single integer: the minimal number of people you have to ask to move seats to make sure the teams sit together.

예제 1
입력
5
ABABC
출력
2
예제 2
입력
12
ABCABCABCABC
출력
6
예제 3
입력
4
ACBA
출력
0
예제 4
입력
6
BABABA
출력
2
예제 5
입력
9
ABABCBCAC
출력
3
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC BAPC 2018

평가 및 의견

G. Game Night

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

G. Game Night

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8