#P9183. Cow Texting Excitement
Cow Texting Excitement
Cow Texting Excitement
Bessie and Elsie are planning to overthrow Farmer John via a series of text messages. Their conversation is represented by a string \(S\) of length \(N\), where each character \(S_i\) is either B
(Bessie) or E
(Elsie). However, some messages have been intercepted and obfuscated by Farmer John and are marked as F
. For each F
in \(S\), the original sender could have been either B
or E
.
The excitement level of a non‐obfuscated conversation is defined as the number of times a cow sends two consecutive messages. In other words, it is the number of occurrences of the substrings \(BB\) or \(EE\) in \(S\). Given \(S\) with some messages obfuscated, determine all possible excitement levels over all substitutions of every F
with either B
or E
.
More formally, if \(S\) is a string of length \(N\) where \(S_i \in \{B, E, F\}\), then for each occurrence of \(F\) you may replace it with either \(B\) or \(E\). Let the excitement level of a fully determined string be the number of indices \(i\) (with \(1 \leq i < N\)) such that \(S_i = S_{i+1}\). Output all distinct possible excitement levels (in increasing order) that can be achieved by such substitutions.
The mathematical definition of the excitement level is given by:
[ \text{excitement}(S) = \sum_{i=1}^{N-1} \mathbf{1}(S_i = S_{i+1}), ]
where \(\mathbf{1}(\cdot)\) is the indicator function.
inputFormat
The input consists of two lines:
- The first line contains an integer \(N\) (the number of messages).
- The second line contains a string \(S\) of length \(N\). Each character of \(S\) is either
B
,E
, orF
.
outputFormat
Output all distinct possible excitement levels (i.e. counts of consecutive identical letters) that can be obtained by replacing every F
by either B
or E
. The values should be printed in increasing order separated by spaces.
sample
3
BFB
0 2