No.769 UNOシミュレータ
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
Problem Statement
N drunkards, assigned ids from 1 to N, are playing UNO. The rules of UNO in this problem are as follows.
- At the start of the game, everyone is dealt some cards (at least 1) (hereafter called their hand). The remaining cards are placed on the table as the draw pile
- The first drunkard to reduce their hand to 0 cards wins (the game ends at that moment)
- For a fair game the numbers of cards dealt should be equal, but since the dealer is drunk, they may not be equal
- Turns start from drunkard 1 and continue with 2,3,... (ascending order of id)
- When a drunkard's turn comes, they choose one card from their hand and play it onto the table
There are the following 5 types of cards.
- number
Has no particular effect.- drawtwo
Makes the next player draw 2 cards from the draw pile (the player made to draw 2 cards cannot play a card on that turn, and the turn passes to the next player). However, this can be avoided by playing a drawtwo on top of it. That is, when you are about to be made to draw cards by a drawtwo, playing a drawtwo lets you pass the turn to the next person without drawing. In this case, the effect of drawtwo accumulates (2+2=4 cards). For example, if 5 players play drawtwo in a row and the 6th player cannot play a drawtwo, the 6th player must draw 2+2+2+2+2=10 cards- drawfour
The 4-card version of drawtwo- skip
Skips the next player- reverse
Reverses the order in which turns pass (ascending order of id->descending order of id, descending order of id->ascending order of id)
A log of the cards played onto the table is given in chronological order. Analyze this log and output, on one line separated by a space, the id of the winner and the number of cards that person held in their hand at the start of the game.
Notes
- In fact, there are cases where the flow of the game cannot be uniquely determined just by looking at the log of played cards.
This happens when drawtwo or drawfour cards appear consecutively. For example, when there are 4 players and the log is given as
drawtwo drawtwo number
the following 2 flows of the game are possible:- Player 1 plays drawtwo, and player 2 draws 2 cards. Player 3 plays drawtwo, and player 4 draws 2 cards. Player 1 plays number
- Player 1 plays drawtwo, player 2 stacks another drawtwo on top, and player 3 draws (2+2=)4 cards. Player 4 plays number
- consecutive drawtwo (drawfour) cards in the log are always interpreted as having been stacked
That is, the second interpretation applies here - A drawfour cannot be stacked on a drawtwo, nor a drawtwo on a drawfour
- The draw pile never runs out
- The given log is guaranteed to be correct. The log ends at the moment someone's hand reaches 0 cards
Input
$N\ M$ $l_1$ $l_2$ $\vdots$ $l_M$
$2 \leq N \leq 10^5$ : the number of drunkards
$1 \leq M \leq 3\cdot10^5$ : the number of log entries
$l_i \in $ { "number", "drawtwo", "drawfour", "skip", "reverse" } : a string representing the i-th card played onto the table
Output
id x
id : the id of the winner ($1 \leq id \leq N$)
x : the number of cards the winner initially held in their hand ($1 \leq x$)
Print a newline at the end.Sample
Sample 1
Input
2 5 skip skip skip skip reverse
Output
1 5
(Player 1 plays skip $\rightarrow$ player 2 is skipped) × 4 $\rightarrow$ player 1 plays reverse and goes out
Drunkard 2 could not play a single card.
Sample 2
Input
4 9 number reverse skip reverse drawtwo drawfour drawfour skip number
Output
3 3
Player 1 plays number$\rightarrow$player 2 plays reverse$\rightarrow$player 1 plays skip$\rightarrow$ player 4 is skipped$\rightarrow$player 3 plays reverse$\rightarrow$player 4 plays drawtwo$\rightarrow$ player 1 draws 2 cards$\rightarrow$player 2 plays drawfour$\rightarrow$player 3 stacks a drawfour$\rightarrow$ player 4 draws 8 cards$\rightarrow$player 1 plays skip$\rightarrow$player 2 is skipped$\rightarrow$player 3 plays number and goes out
Sample 3
Input
3 7 drawtwo reverse number skip number reverse number
Output
2 1
Player 1 plays drawtwo$\rightarrow$player 2 draws 2 cards$\rightarrow$player 3 plays reverse$\rightarrow$ player 2 plays number$\rightarrow$player 1 plays skip$\rightarrow$player 3 is skipped$\rightarrow$ player 2 plays number$\rightarrow$player 1 plays reverse$\rightarrow$player 2 plays number and goes out
Note that the answer is not the number of cards eventually played, but the number of cards held in the hand at the start of the game.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。