P7506 "Wdsr-2.5" Cirno's Arithmetic Game
Description
#### Game Overview
*Cirno's Arithmetic Game* (nickname: "⑨ Cards") is a relaxing and fun multiplayer turn-based card game.
**Note: The rules here are not exactly the same as the common ⑨ Cards rules on the market.** Since there are too many variants of ⑨ Cards and they are hard to handle, the rules here are more similar to the $\text{NEU}$ game.
There are $n$ players sitting in a circle. The game lasts for $m$ rounds. Each player starts with $3$ hand cards. There is a deck with $k$ cards. In this problem, you may assume **the deck will never run out** (really). Also, according to the rules of this problem, you do not need to consider the order of cards in a player's hand.
To describe the game rules more simply, you may think that in each round there is an integer variable (like an $\text{int}$-type register) $p$. The cards played by players are essentially operations on $p$.
**Note**: Please pay attention to the relationship between "game", "round", and "turn" below. In this problem you will play only one game. Each game has $m$ rounds. Each round has several turns, and in each turn exactly one player plays a card.
At the start of each round, $p$ is initialized to $0$. Then, starting from the initial player, players play cards one by one in **clockwise order** ($1,2,3,\cdots n-1,n,1,2,\cdots$; similarly for counterclockwise). If this is the first round, then the initial player is player $1$. After a player plays a card, if $p> 99$ at that time, that player becomes the **loser** of this game; otherwise, she will **immediately draw one card from the top of the deck** and move to the next turn. The loser discards the remaining two cards in her hand, and then draws three cards from the top of the deck in order and puts them into her hand. Meanwhile, the loser becomes the **initial player of the next round**. During one game, the deck only decreases and never increases. Used cards will not return to the deck.
Next, we introduce the card types in this modified version of the game.
#### Basic Cards
Basic cards are divided into five types: addition cards, subtraction cards, multiplication cards, division cards, and fixed-value cards.
- Addition cards: there are $7$ types in total: $A_{1},A_{2},A_{5},A_{9},A_{19},A_{49},A_{99}$. The effect of $A_x$ is to add the number on the card to $p$, i.e. $p\gets p+x$.
- Subtraction cards: there are $3$ types in total: $B_{1},B_{9},B_{19}$. The effect is similar to addition cards, except it subtracts the number on the card from $p$.
- Multiplication cards: there is only $1$ type: $C_2$. Its effect is to multiply $p$ by the corresponding number, i.e. $p\gets p\times x$.
- Division cards: also only $1$ type: $D_2$. It divides $p$ by the corresponding number and **rounds down**, i.e. $p\gets \lfloor p\div x\rfloor$.
- Fixed-value cards: there are $3$ types: $E_{0},E_{49},E_{99}$. They directly set $p$ to the number on the card.
#### Counter Cards
Counter cards are a type of cards that allow a player to skip her turn and apply some special effects.
- $\tt{PASS}$: skip you, move to the next player.
- $\tt{TURN}$: skip you, reverse the playing order (clockwise becomes counterclockwise, and counterclockwise becomes clockwise. It will be reset to clockwise at the beginning of the next round).
- $\tt{DOUBLE}$: skip you, then apply the $\verb!"DOUBLE"!$ effect to the next player, i.e. they must play two cards (play one then draw one, then play one then draw one; they must keep the total always not exceeding $99$ throughout, otherwise they will lose).
Some notes about the $\tt{DOUBLE}$ effect: if you are affected by $\tt{DOUBLE}$, but your first played card is a counter card (any of the three counter cards), then you immediately remove the $\tt{DOUBLE}$ effect, skip this turn, **and transfer the effect to the next player**. The $\tt{DOUBLE}$ effect cannot stack.
---
In the input file, card names will look like $\colorbox{#f0f0f0}\verb!A1 A99 D2 PASS DOUBLE!$, etc.
#### Strategy
This section describes the decision logic of all players in this problem.
If the player will lose no matter what they play, then they will play any card and become the loser (obviously, which card is played will not affect the final result in any essential way). Otherwise, there are two cases:
1. If $\tt{DOUBLE}$ is not applied at this moment:
- Each player will prioritize basic cards, and choose a move that makes $p$ **as large as possible** while not becoming the loser (if there are multiple moves that make $p$ maximal, then they will choose with priority in the order **multiplication card, addition card, subtraction card, division card, fixed-value card**. Obviously, different cards within the same basic-card category will not result in the same value of $p$).
- If there is no basic card, or playing a basic card would make them lose, then they will consider counter cards. They will check whether they have $\tt{PASS,TURN,DOUBLE}$ in this order. If yes, they play that card.
2. If $\tt{DOUBLE}$ is applied:
- Prioritize counter cards. Check $\tt{PASS,TURN,DOUBLE}$ in this order. If yes, play that card.
- Otherwise, choose a move that makes $p$ **as small as possible** while not becoming the loser (if there are multiple moves that make $p$ minimal, then choose with priority in the order **division card, subtraction card, addition card, multiplication card, fixed-value card**). At this time the player will be removed from the $\tt{DOUBLE}$ state, so she will then make decisions according to case $1$.
Input Format
The first line contains three positive integers $n,m,k$, with meanings as described in the statement.
The next $n$ lines each contain four strings $name,card_1,card_2,card_3$, representing the player's name and her three hand cards. Player names consist only of uppercase and lowercase English letters, contain no spaces, and have length at most $20$.
The next line contains $k$ strings, describing the cards in the deck from top to bottom.
Details can be found in the sample input.
Output Format
When a new round begins, output: $\colorbox{f0f0f0}\verb!Round XXX:!$ (where $\verb!XXX!$ indicates which round it is).
Each time a player plays a card, if she is not the loser, output: $\colorbox{f0f0f0}\verb!XXX used YYY,now p=ZZZ.!$ (where $\verb!XXX!$ is the player name; $\verb!YYY!$ is the card name; $\verb!ZZZ!$ is the current value of $p$).
Otherwise, when a player becomes the loser, that round ends. Output: $\colorbox{f0f0f0}\verb!XXX lost the game.!$ (where $\verb!XXX!$ is the player name).
Details can be found in the sample output.
Explanation/Hint
#### Sample 1 Explanation
The usage of the cards is all shown in the sample output. Here we only explain each player's current hand after each card is played. For why a certain card should be used, refer to the statement.
$$
\def\c#1{\texttt{#1}}
\def\arraystretch{1.5}
\begin{matrix}
\begin{gathered}
\textbf{\textsf{Initial}}\cr
\begin{array}{|c|c|c|c|} \hline
\textbf{Player Name} & \textbf{Hand Card 1} & \textbf{Hand Card 2} & \textbf{Hand Card 3} \cr\hline
\text{JoesSR} & \c{B9} & \c{A99} & \c{PASS} \cr\hline
\text{Cirno} & \c{C2} & \c{D2} & \c{A49} \cr\hline
\end{array}\cr
\textbf{\textsf{Turn 1}}\quad (p: 0\to 99)\cr
\begin{array}{|c|c|c|c|} \hline
\textbf{Player Name} & \textbf{Hand Card 1} & \textbf{Hand Card 2} & \textbf{Hand Card 3} \cr\hline
\text{JoesSR} & \c{B9} & \c{E49} & \c{PASS} \cr\hline
\text{Cirno} & \c{C2} & \c{D2} & \c{A49} \cr\hline
\end{array}\cr
\textbf{\textsf{Turn 2}}\quad (p:99\to 49)\cr
\begin{array}{|c|c|c|c|} \hline
\textbf{Player Name} & \textbf{Hand Card 1} & \textbf{Hand Card 2} & \textbf{Hand Card 3} \cr\hline
\text{JoesSR} & \c{B9} & \c{E49} & \c{PASS} \cr\hline
\text{Cirno} & \c{C2} & \c{DOUBLE} & \c{A49} \cr\hline
\end{array}\cr
\textbf{\textsf{Turn 3}}\quad (p:49\to 49)\cr
\begin{array}{|c|c|c|c|} \hline
\textbf{Player Name} & \textbf{Hand Card 1} & \textbf{Hand Card 2} & \textbf{Hand Card 3} \cr\hline
\text{JoesSR} & \c{B9} & \c{PASS} & \c{PASS} \cr\hline
\text{Cirno} & \c{C2} & \c{DOUBLE} & \c{A49} \cr\hline
\end{array}\cr
\end{gathered}
&
\begin{gathered}
\textbf{\textsf{Turn 4}}\quad (p:49\to 98)\cr
\begin{array}{|c|c|c|c|} \hline
\textbf{Player Name} & \textbf{Hand Card 1} & \textbf{Hand Card 2} & \textbf{Hand Card 3} \cr\hline
\text{JoesSR} & \c{B9} & \c{PASS} & \c{PASS} \cr\hline
\text{Cirno} & \c{A19} & \c{DOUBLE} & \c{A49} \cr\hline
\end{array}\cr
\textbf{\textsf{Turn 5}}\quad (p:98\to 89)\cr
\begin{array}{|c|c|c|c|} \hline
\textbf{Player Name} & \textbf{Hand Card 1} & \textbf{Hand Card 2} & \textbf{Hand Card 3} \cr\hline
\text{JoesSR} & \c{A49} & \c{PASS} & \c{PASS} \cr\hline
\text{Cirno} & \c{A19} & \c{DOUBLE} & \c{A49} \cr\hline
\end{array}\cr
\textbf{\textsf{Turn 6}}\quad (p:89\to 89)\cr
\begin{array}{|c|c|c|c|} \hline
\textbf{Player Name} & \textbf{Hand Card 1} & \textbf{Hand Card 2} & \textbf{Hand Card 3} \cr\hline
\text{JoesSR} & \c{A49} & \c{PASS} & \c{PASS} \cr\hline
\text{Cirno} & \c{A19} & \c{A99} & \c{A49} \cr\hline
\end{array}\cr
\textbf{\textsf{Turn 7}}\quad (p:89\to 89)\cr
\begin{array}{|c|c|c|c|} \hline
\textbf{Player Name} & \textbf{Hand Card 1} & \textbf{Hand Card 2} & \textbf{Hand Card 3} \cr\hline
\text{JoesSR} & \c{A49} & \c{A99} & \c{PASS} \cr\hline
\text{Cirno} & \c{A19} & \c{A99} & \c{A49} \cr\hline
\end{array}\cr
\end{gathered}
\end{matrix}
$$
**Note**: In the initial turn and turns $2,4,6$, it is $\text{JoesSR}$ who plays; in turns $1,3,5,7$, it is Cirno who plays. Note that although Cirno used $\tt{DOUBLE}$ on turn $5$, because the next turn was skipped by $\tt{PASS}$, turn $7$ was still played by Cirno.
At this point, Cirno will lose no matter what, so Cirno becomes the loser.
#### Sample 3
See the attached file provided.
#### Constraints
- For $30\%$ of the testdata, only basic cards are included, and $n\le 3$.
- For another $15\%$ of the testdata, there are no $\tt{TURN}$ cards and no $\tt{PASS}$ cards.
- For another $15\%$ of the testdata, there are no $\tt{DOUBLE}$ cards.
- For $100\%$ of the testdata, $1\le n\le 30;1\le m\le 100;1\le k\le 3\times 10^5$. It is guaranteed that at any time $|p|