#P7506. Simulating the Cryptic Card Game

    ID: 20701 Type: Default 1000ms 256MiB

Simulating the Cryptic Card Game

Simulating the Cryptic Card Game

This problem asks you to simulate a modified multiplayer card game. In the game, n players sit in a circle and play m rounds. At the beginning of each round the integer variable \(p\) is set to 0. Each player is dealt 3 cards from a deck that contains \(k\) cards initially (the deck is never exhausted during the game). The players take turns (in either clockwise or counterclockwise order) playing one card each turn. The effect of a played card is applied immediately to the variable \(p\). If after a move, \(p > 99\) then the active player immediately loses the round. When a player loses a round, they discard the rest of the cards in their hand and draw 3 new cards from the deck. This player will also be the first to play in the next round. Note that at the beginning of the very first round, play starts with player 1, and at the beginning of every round the play order is reset to clockwise.

The deck contains two kinds of cards.

Normal Cards

  • Addition Cards: There are 7 types of addition cards, denoted Ax (for example, A1, A99, etc). When a player plays an addition card, the effect is: \(p \gets p + x\).
  • Subtraction Cards: There are 3 types, denoted Bx. Their effect is: \(p \gets p - x\).
  • Multiplication Card: Only one type exists: C2, with effect \(p \gets p \times 2\).
  • Division Card: Only one type exists: D2, with effect \(p \gets \lfloor p \div 2 \rfloor\).
  • Fixed Cards: There are 3 types, denoted E0, E49 and E99. The effect is \(p \gets x\) (i.e. directly setting the value).

Special (Escapist) Cards

  • PASS: Skip your turn (do nothing to \(p\)).
  • TURN: Skip your turn and reverse the play order immediately (clockwise becomes counterclockwise and vice versa). (Note: the play order is reset to clockwise at the beginning of each round.)
  • DOUBLE: Skip your turn and impose a "DOUBLE" effect on the next player. Under the DOUBLE effect the affected player has a different decision criterion (see below).

    When a player who is under the DOUBLE effect uses any special card as his first play in that turn, the DOUBLE effect is immediately canceled on him and transferred to the next player.

Player Strategy:

Case 1: If a player is not under the DOUBLE effect, he will try to play one of his normal cards such that after its effect, \(p\) becomes as large as possible without causing failure (i.e. without making \(p > 99\)). If there are several normal cards that lead to the same \(p\), he chooses according to the following priority order: Multiplication > Addition > Subtraction > Division > Fixed. If no normal card can be played safely, he checks for special cards in the order: PASS, TURN, DOUBLE. If he has none of these, he plays an arbitrary card and loses the round.

Case 2: If a player is under the DOUBLE effect, he will first check for any special card in the order: PASS, TURN, DOUBLE. If he has one, he plays it, releasing the DOUBLE effect on himself and transferring it to the next player. If he does not have any special card, he chooses a normal card so that \(p\) becomes as small as possible (again, only using cards that keep \(p \le 99\)). In this minimization, if several normal cards yield the same \(p\), the priority is: Division > Subtraction > Addition > Multiplication > Fixed. If no normal card can be played safely, he plays an arbitrary card and loses the round.

After playing a card (whether normal or special) and if no failure occurs, the player immediately draws one card from the top of the deck.

Your task is to simulate the game for m rounds. For each round, output two numbers on a separate line: the ID of the player who loses this round and the value of \(p\) right after the card that caused the loss.

Note: The initial hands are dealt by giving each of the n players 3 cards drawn from the top of the deck in order. Afterwards, all draws (including those after a non‐losing play and after a loss) are taken from the top of the remaining deck. It is guaranteed that the deck is sufficiently large.

inputFormat

The input begins with a line containing three integers: n (number of players), m (number of rounds), and k (total number of cards in the deck).

The next line contains k strings representing the cards in the deck (from top to bottom), separated by spaces. The card names will be exactly as described above (for example: A1, A99, D2, PASS, DOUBLE, etc.).

Note: The first 3*n cards of the deck are automatically dealt to the players in order (player 1 receives the first 3 cards, player 2 the next 3, and so on). The rest of the deck is used for drawing during the game.

outputFormat

Output m lines. Each line should contain two integers: the ID of the player who lost the round and the value of \(p\) at the time of failure in that round.

sample

3 2 30
A99 A1 B1 A49 TURN B9 C2 PASS E0 A19 D2 DOUBLE B19 E49 A9 A9 A5 A2 TURN E99 A1 C2 E0 B1 TURN A9 B9 D2 A49 PASS
3 107