Aaawww... or Aaayyy!!!
Time limit2sMemory limit1024 MB
Given a frozen scoreboard and the pending submissions in reveal order, find the final rank of your favourite team from the length of each chant.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation, String
- Solved
- No attempts yet
Problem
You are a hardcore supporter for one of the teams at the Benelux Algorithm Programming Contest (BAPC). The staff caught you entering the contest area and popping other teams' balloons, so you were kicked out of the building until the contest is over. You do not want to miss the award ceremony and be the only person who does not know the final rank of your favourite team while everyone inside already knows. Luckily, you know a way to follow the ceremony from outside.
One hour before the end of the contest, the scoreboard freezes. You can access the frozen scoreboard online, so you know the rank of each team and whether each of its submissions is accepted, rejected, or pending. During the award ceremony, the results of the pending submissions are revealed one at a time. The next submission to reveal is the leftmost pending submission of the lowest ranking team that has a pending submission. After every reveal, the scoreboard is updated and the next submission is chosen the same way.
Before a pending result is revealed, the audience chants Ooohhh.... If the submission is rejected, the audience chants a sad Aaawww.... If it is accepted, the crowd cheers with Aaayyy!!!. When an accepted submission raises a team in the ranking, the cheer gets longer: one extra y is added for each team that the team passes. For example, if a team passes five teams, the audience yells Aaayyyyyyyy!!! with eight ys. You cannot make out the announcer's words, but you can hear the audience clearly from outside. You want to use the chants to determine the final rank of your favourite team.
Input
The first line contains three integers , , and (, , ), the number of teams, the number of problems, and the rank of your favourite team in the frozen scoreboard.
The next lines each contain characters. Each character is A, R, P, or N, meaning accepted, rejected, pending, or nothing for that team and problem. The teams are sorted by rank in the frozen scoreboard, in descending order of accepted submissions. Tie-breaking rules guarantee that all teams have distinct ranks.
For each pending submission, one line follows with two strings: the chant at the reveal, in chronological order. The first string is Ooohhh.... The second string is Aaawww... or Aaayyy!!!, with one extra y for each team passed.
Output
Print the final rank of your favourite team.