問題一覧 > 通常問題

No.714 回転寿司屋のシミュレート

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 187
作問者 : horiesiniti / テスター : mai
お気に入りにしたユーザー ProblemId : 1223 / 自分の提出
問題文最終更新日: 2026-06-25 18:29:42
Simulating a Conveyor Belt Sushi Restaurant
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
yukicoder contest 195 (順位表) の他の問題:

Problem Statement

We will run a simplified simulation of a conveyor belt sushi restaurant.
The seats in the restaurant are numbered from 1 to 20.
Once the restaurant opens, customers arrive and take seats. Each customer holds a list of foods they want to eat (there are even extreme customers, such as one whose list is 10 plates of horse mackerel). When a sushi topping on their list reaches them, they always take it, and one plate of it is removed from their list.
Sushi flows one piece at a time past seats 1 through 20, and is discarded if nobody takes it.
The data is given one line at a time in chronological order.
The types of data are as follows.

Data 0
A customer sits in seat i, and their list of foods they want to eat is given.
Data 1
One plate of sushi is sent down the conveyor belt and passes seats 1 through 20 in order.
Data 2
The customer in seat i goes to pay the bill.
Multiple customers never sit in the same seat, and a customer never leaves from a seat where nobody is sitting.
Each time Data 1 is given, answer on one line with the seat number of the customer who takes the sushi.
If nobody takes it, output -1.
Depending on the dataset, Data 1 may come first.

Input

$N$
$U_1$
$\dots$
$U_n$

2 $\le$ $N$ $\le$ 5005, where N is the number of data entries.
Each Ui is given on one line and is one of the following 3 types of data.

Data 0
0 $n_i$ $m_i$ $A_{(i,1)}$ $\dots$ $A_{(i,mi)}$

A customer sits in seat $n_i$, and their list of foods they want to eat consists of $m_i$ items.
$A_(i,j)$ is the type of sushi topping they want to eat.

The input also satisfies the following constraints.
$ 1 \le n_i \le 20$
$ 1 \le m_i \le 10$
$ 1 \le |A_{i,m_i}| \le 17$
$A_{i,m_i}$ consists of lowercase letters and has at most 17 characters.

Data 1
1 $B_i$

Sushi topping $Bi$ passes seats 1 through n in order. If it passes in front of a customer who has it on their list, that customer takes it, and exactly one of that topping is removed from their list. For example, when a customer takes horse mackerel, two on the list become one, and one becomes zero and disappears.
$B_i$ is the name of a sushi topping in lowercase letters.

Data 2
2 $C_i$

The customer in seat $C_i$ goes to pay the bill, and that customer's list of foods they want to eat disappears.

$1 \le C_i \le 20$
All data is given separated by spaces. The number of chairs is fixed at 20 seats. Sushi toppings are written in alphabetic letters and have at most 17 characters.
You may assume that there are at most 53 types of sushi toppings.

Output

$b1$
$\dots$
$bx$
Print a newline at the end.

Each output $bi$ is the seat number, on one line, of the customer who takes the plate when Data 1 is given.
If the plate goes all the way around without any customer taking it, it is discarded; output -1.

Sample

Sample 1
Input
11
1 toro
1 unagi
0 14 4 maguroakami hotatekai unagi maguroakami
1 saamonnmottu
1 unagi
1 unagi
1 maguro
1 kouika
1 maguroakami
1 maguroakami
2 14
Output
-1
-1
-1
14
-1
-1
-1
14
14

The first 2 plates are discarded because there are no customers, giving -1. Only the customer in seat 14 sits down. unagi comes by twice, but the customer in seat 14 wants only one plate of unagi, so the second plate is passed over. maguroakami comes by twice, and the customer in seat 14 wants 2 plates of maguroakami, so they take the second plate as well. The remaining plates are not ones the customer wants, so they are passed over and discarded.

Sample 2
Input
15
0 14 4 maguroakami hotatekai unagi maguroakami
1 hotatekai
1 hotatekai
0 15 3 maguroakami saamonnmottu hotatekai
1 hotatekai
1 saamonnmottu
1 unagi
1 unagi
1 maguro
1 kouika
1 maguroakami
2 14
1 maguroakami
1 maguroakami
2 15
Output
14
-1
15
15
14
-1
-1
-1
14
15
-1

There is demand for 3 plates of maguroakami, but since the customer in seat 14 has left, the third plate of maguroakami is not taken. The rest is as you can see. Although it does not happen in this sample case, a new customer may of course sit in a seat that a customer has left.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。