Back
Close
  • 24

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

Statement

 Goal

In an amusement park, people are queuing for the ride through the Haunted Mansion.

A ride consists of 10 wagons, with each wagon having 2 seats. So each ride can support up to 20 people.
A visual representation of an empty ride is as follows (each D represents an empty seat, the rest are the visuals of the ride):

/< | D | D | D | D | D | D | D | D | D | D |
\< | D | D | D | D | D | D | D | D | D | D |

The ride is moving from right to left, so the first wagon is on the left and last wagon is on the right in the picture above. This also means that in each wagon, the seat at the top row is on the right side of the wagon.

There are multiple groups of people queueing for the ride, and you are a kid in one of the groups. Your task is to output the ride number and the visual representation of the ride you are on according to the following rules:

Intra group rules:
1. Kids must be seated next to an adult.
2. In each wagon, the right seat must be filled first before the left seat.
3. In each wagon, adult is seated first before kid.
4. You will always be the first seated kid of your group.

Inter group rules:
5. People from the same group must all sit in the same ride.
6. Two people from different groups can't be seated on the same wagon.
7. If it's not possible to fulfill the above rules (e.g., a group of only kids, violating rule 1), the group is rejected from the ride.

Ride departure rules:
8. A ride is filled from the front to the back.
9. Once the ride can't fit the next group in the queue (excluding groups that are rejected) according to above rules, the ride departs, and the next ride (which is empty) comes in.

When outputting the visual representation of a filled ride, A represents an adult, k represents a kid, and x represents you.

Examples:

Rule 1: Kids must be seated next to an adult
Example with group of 3 people (2 adults + 1 kid) : AAk

/< | A | A | D | D | D | D | D | D | D | D |
\< | k | D | D | D | D | D | D | D | D | D |


Rule 3: In each wagon, adult is seated first before kid.
Example with 1 adult + 1 kid: kA

Right side /< | A | D | D | D | D | D | D | D | D | D |
Left side \< | k | D | D | D | D | D | D | D | D | D |


Rule 6: Two people from different groups can't be seated on the same wagon.
Example with 2 group of 3 people per group: AAk AAAkk

/< | A | A | A | A | A | D | D | D | D | D |
\< | k | D | k | k | D | D | D | D | D | D |
Input
Line 1: A number N representing the number of groups
Line 2: A string S representing the groups in the queue. Groups are separated by a space.
A represents an adult
k represents a kid
x represents you
Output
Line 1: A number M that represents the ride number you are on. The first ride has M=1.
Line 2-3: The visual representation of the ride that you are on.
Constraints
0 < N < 20
0 < S < 1024
Example
Input
1
AAx
Output
1
/< | A | A | D | D | D | D | D | D | D | D |
\< | x | D | D | D | D | D | D | D | D | D |

A higher resolution is required to access the IDE