No.893 Guide the Customers
Problem Statement
Gyopuro Supermarket has $N$ checkout registers with automatic payment machines and 1 register where payment is handled by hand.
The $N$ registers are numbered from $1$ to $N$.
However, one day the payment system was suddenly hacked and became unusable.
Since the automatic payment machines can no longer be used, it was decided to guide all customers to line up in a single line at the register where payment is handled by hand.
The guidance is carried out according to the following rules.
- Operation: for a given register, guide the customer at the front of its line to the end of the line at the register where payment is handled by hand. As a result, the second customer becomes the front.
- The operation is performed in ascending order of register number. After register number $N$ is done, it returns to 1 again.
- The above is repeated until all customers have finished moving.
Furthermore, for convenience, customers are also assigned numbers with no duplicates, and there is at least 1 customer.
Also, the register where payment is handled by hand is normally closed because of its inefficiency, so no customers are lined up there initially.
Given the number of registers and the number of customers lined up at each register along with their numbers, output the order of the customers after the moves are finished, from the front of the line.
Input
$N$ $P$$1$ $A$$1,1$ $A$$1,2$$\dots A$$1,p$$1$ $P$$2$ $A$$2,1$ $A$$2,2$$\dots A$$2,p$$2$ $\dots$ $P$$N$ $A$$N,1$ $A$$N,2$$\dots A$$N,p$$N$$N$ is the number of registers.
In the following $N$ lines, the number of people $P$$i$ lined up at the $i$-th register and the numbers of those $P$$i$ people are given.
That is, $A$$i,j$ is the number of the $j$-th customer from the front at the $i$-th register.
$1\le N \le 10$$3$
$0$ $\le$ $P_i$ $\le$ $10$$2$
$1$ $\le$ $A$$i,j$$\le 10$$5$
When $(i,j) \neq (ii,jj)$, $A$$i,j$$\neq$$A$$ii,jj$
At least one $A$$i,j$ exists
Output
Output the order of the customers, from the front, after all customers have finished moving to the register where payment is handled by hand, separated by spaces.
Print a newline at the end.
Sample
Sample 1
Input
3 3 1 2 3 2 4 5 1 6
Output
1 4 6 2 5 3
There are 3 registers:
customers 1,2,3 are lined up at register 1, customers 4,5 at register 2, and customer 6 at register 3.
Since the front customer is moved in ascending order of register number,
the customers could be moved in the sequence {1} {1,4} {1,4,6} {1,4,6,2} {1,4,6,2,5} {1,4,6,2,5,3}.
Sample 2
Input
5 3 1 2 3 0 1 4 2 5 6 0
Output
1 4 5 2 6 3There may be registers where no customers are lined up initially.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
gotutiyan