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

31155번 - Jason ABC 스페셜 저지다국어

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

문제

You are given a string $S$ of length 3ドルn,ドル consisting of the characters A, B and C. You are allowed to perform the following operation:

  • Select some subsegment of this string and a character $c$ (one of A, B and C). Then, replace all the characters on the subsegment with $c$.

Find the smallest number of times that you would have to apply the operation above to get a string which contains each of characters A, B and C exactly $n$ times. It can be shown that it is always possible to get such a string.

In addition, find a sequence of operations of the smallest possible length. If there are many such sequences, you can output any of them.

입력

The first line of input contains a single integer $n$ (1ドル \le n \le 3 \cdot 10^5$).

The second line of the input contains a string $S$ of length 3ドルn,ドル consisting of the characters A, B and C.

출력

In the first line print the minimum number of operations $k$.

In the $i$-th of the next $k$ lines print 2ドル$ integers $l_i, r_i$ and a character $c_i$ (1ドル \le l_i \le r_i \le 3n,ドル $c_i \in \{$A, B, C$\}$), denoting that in the $i$-th operation you will replace each of the characters $S_{l_i}, S_{l_i+1}, \ldots, S_{r_i}$ with $c_i$.

If there is more than one solution with a minimum number of operations, you can print any one of them.

제한

예제 입력 1

1
AAA

예제 출력 1

2
2 3 B
3 3 C

예제 입력 2

1
CAB

예제 출력 2

0

예제 입력 3

3
ABABCABAB

예제 출력 3

1
1 2 C

노트

In the first sample, the string will undergo the following transformations:

AAA $\to$ ABB $\to$ ABC.

In the second sample, the string already contains exactly one A, one B and one C.

In the third sample, the string will undergo the following transformation:

ABABCABAB $\to$ CCABCABAB. Now, it contains each letter 3ドル$ times.

출처

Contest > Open Cup > 2021/2022 Season > Stage 7: Grand Prix of Southeastern Europe J번

ICPC > Regionals > Europe > Southeastern European Regional Contest > SEERC 2021 L번

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

출처

대학교 대회

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

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