Loading...
Alibaba wants to escape
Time: 1 s
Memory: 125 MB
Now, Alibaba is trapped inside the cave. He discovers several treasure boxes and collects all the treasure. However, in order to escape, he must successfully complete a magical game, consisting of \(\boldsymbol{n}\) rounds. Each round results in one of the following outcomes:
 
  • A win, denoted by 'W', earns 1 point.
  • A loss, denoted by 'L', loses 1 point.
  • A draw, denoted by 'D', earns 0 points
You are given a string \(\boldsymbol{s}\) of length \(\boldsymbol{n}\), consisting of the characters 'W', 'L', or 'D', where each character represents the result of a round.
Additionally, you are given an integer \(\boldsymbol{k}\) (1-based index), indicating that the outcome of the \(\boldsymbol{k^{th}}\) round can be changed to any of 'W', 'L', or 'D'.

After making this change, determine all distinct scores achievable from every possible contiguous subsegment of rounds in the updated string. The score of a subsegment is the sum of the points corresponding to each round within it.

Among all possible modifications to the \(\boldsymbol{k^{th}}\) round, choose the one that:
  • Maximizes the number of distinct subsegment scores.
  • If multiple modifications result in the same number of distinct scores, select the one that produces the highest number of distinct positive scores.
Input
The first line contains an integer \(\boldsymbol{n} \)\(\)\(k\) \(\) — the total number of rounds, the 1-based index of the round whose outcome can be changed.
The second line contains a string \(\boldsymbol{s}\) of length \(\boldsymbol{n}\), consisting only of the characters 'W', 'L', or 'D'.
Constraint
\(\begin{align*} \text 1 &\leq n \leq 10^5 \\ \text1 &\leq k \leq n \end{align*}\)  
Output
On the first line, output \(\boldsymbol{m}\) — the total number of distinct scores. 
On the second line, output \(\boldsymbol{m}\) space-separated integers — the distinct scores in any order.
Examples
Input
Output
2 1
DW
3
0 -1 1
Input
Output
3 2
WLD
3
1 2 0
Notes
In Test Case 2:
Optimal Change: Change the 2nd character 'L' to 'W', resulting in the updated string "WWD".
Subsegments and their scores:
  • [1, 1] → "W" → 1
  • [1, 2] → "WW" → 1 + 1 = 2
  • [1, 3] → "WWD" → 1 + 1 + 0 = 2
  • [2, 2] → "W" → 1
  • [2, 3] → "WD" → 1 + 0 = 1
  • [3, 3] → "D" → 0
Distinct scores: {1, 2, 0}
Total distinct scores: 3 (2 positive)
This change is optimal, as it maximizes both the total number of distinct scores and the number of distinct positive scores.
Problem Info
Problem ID 483
Time Limit 1000 ms
Memory Limit 128000 KB
Moderators MahD , mahdi_talukder , muhimin , Royboy01
Statistics
Submit
You need to Login or Registration for submit your solution