#arc177b. B - Puzzle of Lamps
B - Puzzle of Lamps
Score: points
问题陈述
AtCoder先生创建了一个由个小灯泡组成的设备,这些灯泡从左到右排列成一行,并且有两个开关A和B。每个灯泡可以处于两种状态之一:0
(关闭)和1
(打开)。按下每个开关会导致以下情况:
- 按下开关A将最左边的灯泡状态从
0
变为1
。 - 按下开关B将最左边的灯泡状态从
1
变为0
。
如果没有适用的灯泡,则不能按下开关。
最初,所有灯泡都处于0
状态。他希望灯泡的状态从左到右依次为。确定按下开关的顺序和次数,以实现这一点。没有必要最小化按下的次数,但应该最多为,以便操作可以在现实时间内完成。可以证明,在这个问题的约束条件下,存在解决方案。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
Mr. AtCoder has created a device consisting of small light bulbs arranged in a row from left to right, and two switches A and B. Each light bulb can be in one of two states: 0
(OFF) and 1
(ON). Pressing each switch causes the following:
- Pressing switch A turns the leftmost light bulb in the
0
state into1
. - Pressing switch B turns the leftmost light bulb in the
1
state into0
.
If there is no applicable light bulb, you cannot press the switch.
Initially, all light bulbs are in the 0
state. He wants the states of the light bulbs to be from left to right. Determine the order and number of times the switches should be pressed to achieve this. It is not necessary to minimize the number of presses, but it should be at most so that the operations can finish in a realistic time. It can be proved that a solution exists under the constraints of this problem.
Constraints
- Each of is
0
or1
. - Not all of are
0
. - is an integer.
Input
The input is given from Standard Input in the following format:
Note that the second line is given as a string of length .
Output
If your solution presses the switches times in the order (each being A
or B
), print those in the following format:
The second line should be printed as a string of length .
Sample Input 1
5
01100
Sample Output 1
4
AAAB
This sample output presents a solution that presses the switches in the order A, A, A, B. This sets the light bulbs to the desired states, as shown in the figure below:
Alternatively, pressing switches in the order A, A, B, A, A, B also sets the light bulbs to the desired states. The following output corresponding to this solution would also be accepted:
6
AABAAB