Colorville
Time limit1sMemory limit128 MB
Simulate players advancing on a colored board by drawing cards, and report who wins or that the deck ran out.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation, Array, String matching
- Solved
- No attempts yet
Problem
A simple color-matching game for children is played on a board that is a single row of colored squares. Every player has one piece, and all pieces begin at START, just before the first square.
Players take turns in a fixed order — Player 1, then Player 2, and so on — each drawing the next card from a deck. A card shows either one colored square or two colored squares of the same color. On their turn a player moves their piece forward:
- If the card shows a single color, move forward to the next square of that color.
- If the card shows two squares of the same color, move forward to the second such square of that color.
- If no such square lies ahead, move forward to the last square of the board.
A player wins the instant their piece lands on the last square. It is possible for the whole deck to be drawn without anyone winning.
Colors are written as capital letters A–Z. Here is an example board (the leftmost square is the START side, the rightmost square is the FINISH side):
Consider the deck R, B, GG, Y, P, B, P, RR. With 3 players the game proceeds as follows:
- Player 1 draws
Rand moves to the 1st square. - Player 2 draws
Band moves to the 5th square. - Player 3 draws
GGand moves to the 8th square. - Player 1 draws
Yand moves to the 2nd square. - Player 2 draws
Pand moves to the 11th square. - Player 3 draws
Band moves to the 9th square. - Player 1 draws
Pand moves to the 4th square. - Player 2 draws
RRand wins — there is noRahead of the piece, so it advances to the last square.
Using the same board and deck with 2 players, Player 1 wins after 7 cards. With 4 players, no one wins after the deck of 8 cards is exhausted.
Input
The input contains one or more games. Each game starts with a line of three integers: the number of players (1–4), the number of squares on the board (1–79), and the number of cards in the deck (1–200). The next line is a string of capital letters listing the board's square colors, one letter per square, from the START side to the FINISH side. The following lines are the deck — one card per line, in the order they are drawn — where each card is a single capital letter or the same capital letter written twice.
The input ends with a line whose first value is 0 (zero players); the other two values on that final line are present but meaningless.
Output
For each game, print exactly one line:
- If a player reaches the last square, print
Player X won after N cards., whereXis the winning player's number andNis the total number of cards drawn (including the winning card). - If the deck is exhausted with no winner, print
No player won after N cards., whereNis the number of cards in the deck.
Always use the plural word "cards", even when N is 1.