C - String Invasion
Editorial
/


Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
長さ の文字列 が与えられます。 の 文字目を で表します。以下の操作を繰り返せる回数の最大値を求めてください。
- 連続する 文字 であって、 であるものを選ぶ。 を で置き換える。
制約
- は英小文字からなる
入力
入力は以下の形式で標準入力から与えられる。
出力
操作を繰り返せる回数の最大値を出力せよ。
入力例 1Copy
Copy
accept
出力例 1Copy
Copy
3
以下のように 回の操作を行うことができます。
- に対して操作を行う。操作後の文字列は
acccpt
になる。 - に対して操作を行う。操作後の文字列は
acccct
になる。 - に対して操作を行う。操作後の文字列は
accccc
になる。
入力例 2Copy
Copy
atcoder
出力例 2Copy
Copy
0
入力例 3Copy
Copy
anerroroccurred
出力例 3Copy
Copy
16
Score : points
Problem Statement
Given is a string of length . Let denote the -th character of . Find the maximum number of times the following operation can be done.
- Choose three consecutive characters in , , such that , and replace with .
Constraints
- consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum number of times the operation can be done.
Sample Input 1Copy
Copy
accept
Sample Output 1Copy
Copy
3
We can do the operation three times, as follows:
- do it with , changing the string to
acccpt
; - do it with , changing the string to
acccct
; - do it with , changing the string to
accccc
.
Sample Input 2Copy
Copy
atcoder
Sample Output 2Copy
Copy
0
Sample Input 3Copy
Copy
anerroroccurred
Sample Output 3Copy
Copy
16