I Could Have Won
InterviewTime limit1sMemory limit1024 MB
Given a string of point winners, find every k where Alice wins more games than Bob under the first-to-k rule.
- Level
Easy3 of 10
- Topics
- Brute force, Simulation, Implementation
- Solved
- No attempts yet
Problem
"We will be closing in about 5 minutes. Thank you for visiting the ICPC gym today."
With this announcement, Alice and Bob stopped playing their rock-paper-scissors marathon in the middle of the th game. Each player scores a point if their throw beats the other player's throw. Each game was played by the first-to-11 rule, meaning that whoever scores points first wins the game. Today, Bob narrowly defeated Alice by a single game. He scored 11 points first in five games, while Alice scored 11 points first in four games.
After carefully inspecting how each game was played, Alice realized that she could have won more games than Bob if they had played under a different rule, such as first-to-5 or first-to-8, instead of the regular first-to-11.
Given the sequence of points scored by Alice and Bob, determine all values of such that Alice would have won more games than Bob under the first-to- rule.
Both Alice and Bob start each game with zero points. As soon as one player reaches points, that player wins the game, and a new game starts. Alice wins a game if she scores points before Bob does. If the gym closes during a game and neither player has reached points, that game has no winner.
Input
The single line of input is a string of uppercase letters "A" or "B", denoting who scored each point from the beginning of the marathon. "A" means Alice scored the point, and "B" means Bob scored the point. The length of the string is between and , inclusive.
Output
On the first line, output the number of positive integers for which the first-to- rule would have made Alice win more games than Bob. If this number is not zero, output all such values of on the next line in increasing order, separated by spaces.