Strange Machine
InterviewTime limit3sMemory limit1024 MB
Given a button press sequence where some presses are unknown (-1), find which of the four bulbs can be lit after the last press.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Simulation
- Solved
- No attempts yet
Statement
The machine has four bulbs: red, green, blue, and yellow. Exactly one bulb is lit at any time. When the machine is started, the red bulb is lit.
The machine has two buttons, 0 and 1. Pressing a button changes which bulb is lit.
- If red is lit, pressing either button lights green.
- If green is lit, pressing 0 lights red, and pressing 1 lights blue.
- If blue is lit, pressing 0 lights yellow, and pressing 1 keeps blue lit.
- If yellow is lit, pressing 0 keeps yellow lit, and pressing 1 lights red.
Juku wrote down the sequence of button presses. His sister Juta dropped the paper into a muddy puddle, and some symbols are now unreadable. Help Juta find every bulb that could be lit after the last press.
Input
The first line contains the number of presses ().
The second line contains integers separated by spaces. Each value is , , or . A means button 0 was pressed, and a means button 1 was pressed. A marks a position the water damaged, so button 0 or button 1 was pressed there.
Output
Print four lines. The first line is the answer for red, the second for green, the third for blue, and the fourth for yellow. Print JAH if that bulb can be lit after the last press, and EI if it cannot.