#P7389. Alice and Bob's Stone Game
Alice and Bob's Stone Game
Alice and Bob's Stone Game
Alice and Bob are playing a game. Initially, Alice has \(n\) stones and Bob has \(m\) stones. They play several rounds. In the \(i\)-th round, the loser must give \(i\) stones to the winner. The game stops when in some round the losing player does not have enough stones to pay.
Your task is to determine the maximum number of rounds that can be played (excluding the round in which the game stops) and to construct a win-loss sequence of length equal to that number. The sequence should consist only of letters A
and B
, where A
indicates that Alice wins the round (so Bob pays \(i\) stones) and B
indicates that Bob wins (so Alice pays \(i\) stones). It is guaranteed that there exists a sequence such that at any moment in the game, both players have a nonnegative number of stones.
Note: All formulas are rendered in \(\LaTeX\)
format.
inputFormat
The input consists of two integers \(n\) and \(m\) which represent the initial number of stones for Alice and Bob respectively.
outputFormat
Output the maximum number of rounds \(k\) that can be played followed by a newline and a string of length \(k\) representing the win-loss sequence. In the sequence, A
indicates that Alice wins the round, while B
indicates that Bob wins the round.
sample
2 2
2
AB
</p>