P5013 Water Bullfight
Background
Newbie ${\rm CYJian}$ dragged ${\rm JerryC}$, ${\rm Justin}$, and a group of big shots from the computer lab to play Bullfight!!
Description
There are now $N$ people playing Bullfight. A total of $T$ rounds are played. In each round, three people participate, and everyone starts with a score of $0$.
For convenience, this problem makes some small changes to the basic rules of Bullfight. The detailed rules are as follows.
### 1. Basic Rules
At the start of each Bullfight round, each player receives $5$ cards.
Each card is either an integer from $2$ to $10$ or `A` (which represents $1$).
Each card has a suit: `a` for spades, `b` for hearts, `c` for clubs, and `d` for diamonds.
### 2. Hand Types
Among the five cards, except for Bomb and No Bull, every hand is divided into two parts: Bull and Points.
- The Bull part consists of either three cards with the same rank (Iron Plate), or three cards whose ranks sum to a multiple of $10$.
- The Points part consists of the remaining two cards. The points of a hand is the remainder of the sum of these two cards modulo $10$.
The hand types are:
(1) Bomb: four cards with the same rank.
(2) Bull Bull: the points is exactly $0$.
(3) Bull: the points is not $0$, and the value of the points equals the bull number. For example, if the points is $5$, then this hand is called Bull Five.
(4) No Bull: there do not exist three cards whose ranks are all the same, or whose rank sum is a multiple of $10$.
### 3. Hand Ranking Rules
Bomb $>$ Bull Bull $>$ Bull Nine $>$ Bull Eight $>$ $\cdots$ $>$ Bull Two $>$ Bull One $>$ No Bull.
If both sides have Bomb, the Bomb with the larger rank is larger.
If the bull number is the same and only one side has an Iron Plate, the one with an Iron Plate is larger.
If the bull number is the same and both sides have an Iron Plate, the Iron Plate with the larger rank is larger.
If the bull number is the same and neither side has an Iron Plate, or both sides have No Bull, compare the highest-rank card in each hand. The side with the larger highest card is larger. If the highest card ranks are equal, compare suits: spades $>$ hearts $>$ clubs $>$ diamonds.
### 4. Scoring
The base score of a hand is $10$, meaning each player bets $10$ points.
For any two players, after comparing their hand types, we take the larger hand type (between the two) to determine the score multiplier for the gain/loss. The rules are:
(1) Bomb: base score $\times 10$.
(2) Bull Bull: base score $\times 3$.
(3) Bull Seven / Bull Eight / Bull Nine: base score $\times 2$.
(4) Bull Six to Bull One: base score.
(5) No Bull: base score.
(6) Iron Plate: after computing the hand-type score, multiply by $2$ based on that score. Note that the Iron Plate multiplier is not applied together with Bomb.
Scoring is done pairwise. That is, for three players A, B, and C, we first compute the score gain/loss between A and B, then between A and C, and finally between B and C.
Now assume all players are smart enough, meaning every player will always play the largest possible hand type from the cards in their hand. ${\rm CYJian}$ wants to know, after these $T$ rounds, the final score of each player.
Input Format
The first line contains three integers $id, T, N$. Here $id$ is the test point index, which may be helpful for partial scoring. In the samples, the test point index is $0$.
The next $N$ lines each contain a string of length less than $11$ consisting only of letters (uppercase/lowercase) and digits, representing a player name.
Then follow $T$ groups. Each group has six lines, and can be viewed as three identical parts:
- The first line contains a string: the player name.
- The second line contains five strings: the player’s five cards. For each string, the first character is the suit, and the remaining characters represent the rank.
Output Format
Output $N$ lines. Each line contains a string and an integer, separated by a space, representing a player and their final score.
Please output in the same order as the player names are given in the input.
Explanation/Hint
Explanation for Sample 1.
In the first round, the hand types are:
${\rm CYJian}$: Bomb
${\rm JerryC}$: Bull Five
${\rm Justin}$: Iron Plate Bull Bull
So ${\rm CYJian}$ gains $200$ points, ${\rm JerryC}$ loses $160$ points, and ${\rm Justin}$ loses $40$ points.
In the second round, everyone has Bull Five, but ${\rm CYJian}$ has the spade five, ${\rm JerryC}$ has the heart five, and ${\rm Justin}$ has the club five. So ${\rm CYJian}$ gains $20$ points, ${\rm JerryC}$ does not change, and ${\rm Justin}$ loses $20$ points.
Constraints:
| Test Point Index | $T$ | $N$ | Special Property |
| :--------------: | :------: | :-----: | :--------------: |
| $1$ | $0$ | $3$ | Property 4 |
| $2$ | $5$ | $5$ | Property 4 |
| $3$-$4$ | $5$ | $5$ | Property 1 |
| $5$-$6$ | $5$ | $5$ | Property 2 |
| $7$-$8$ | $5$ | $5$ | Property 3 |
| $9$-$10$ | $5$ | $5$ | Property 5 |
| $11$-$12$ | $10$ | $10$ | Property 5 |
| $13$-$14$ | $100$ | $100$ | Property 5 |
| $15$-$16$ | $1000$ | $1000$ | Property 5 |
| $17$-$18$ | $10000$ | $10000$ | Property 5 |
| $19$-$20$ | $100000$ | $100000$ | Property 5, $1.5\text{s}$ |
Property 1: It is guaranteed that everyone has a Bomb.
Property 2: It is guaranteed that all suits in each hand are the same.
Property 3: It is guaranteed that all ranks in each hand are different.
Property 4: It is guaranteed that the testdata is handcrafted.
Property 5: It is guaranteed that the testdata is randomly generated.
It is guaranteed that there are no repeated cards within any round.
It is guaranteed that every player has a unique name.
It is guaranteed that the problem setter is ${\rm CYJian}$.
It is guaranteed that the data has no bugs.
It is not guaranteed that someone can solve it.
It is not guaranteed that the code for this problem is very long.
Translated by ChatGPT 5