IHWCPenalty
SRM 846 · 2023-05-22 · by misof
Problem Statement
This problem is inspired by the currently running Ice Hockey World Championships.
In this problem we will simulate a penalty box during a hockey game.
The current hockey game is played between the Lowercase Lions and the Uppercase Urchins. We will use some letters to denote game actions as follows:
- 'p': a player of Lowercase Lions was sent to the penalty box
- 's': a player of Lowercase Lions has finished serving their penalty and has returned from the penalty box
- 'g': the Lowercase Lions scored a goal
- 'P', 'S', 'G': the same for the Uppercase Urchins
If team X has fewer players in the penalty box than team Y, we say that team X is playing a power play and that team Y is playing short-handed. If a team scores a goal during their power play, one player of the opposing team returns from the penalty box. In all other cases the goal has no effect on the penalty box.
You are given the
The answer you should return is a
Constraints
- events will contain between 0 and 1000 characters, inclusive.
- Each character in events will be one of "psgPSG".
- The characters 's' and 'S' will never be used in a situation in which the penalty box contains no players from the respective team.
"gggGgGg" Returns: "======="
Lowercase Lions won this game 5:2. There were no penalties, so all goals were scored at equal strength.
"PPggg" Returns: "PP="
Two players of the Urchins were sent to the penalty box. Then, the Lions scored a power-play goal (which returned one of the punished Urchins' players), another power-play goal, and finally a goal at equal strength.
"PPpPGGg" Returns: "SSP"
Three Urchins and one Lion were sent to the penalty box. Then the Urchins scored two short-handed goals, and finally the Lions scored a power-play goal. At the end of the game there were still two Urchins and one Lion in the penalty box.
"gGpPgGgGsSgG" Returns: "========"
All goals in this game were scored at equal strength -- some of them in the situation when each team had one player in the penalty box.
"GgpPPGgg" Returns: "==SP="
Short-handed goals have no effect on the penalty box. Hence, after the third goal of this game the penalty box still contains one Lion and two Urchins. The fourth goal is a power-play goal for the Lions. After that goal one Urchin returns from the penalty box, so now each team has one player serving a penalty and the fifth goal is scored at equal strength.
"ggPPgSg" Returns: "==P="
One of the two Urchins' penalties is ended by the third goal of the game, the other penalty then expires. By the time the fourth goal is scored the penalty box is empty again.
Submissions are judged against all 86 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class IHWCPenalty with a public method string resolve(string events) · 86 test cases · 2 s / 256 MB per case