Logo
(追記) (追記ここまで)

33188번 - Monster Warehouse 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB405521.739%

문제

Mike and Sally work in the warehouse of Monster Inc. as storekeepers. Their daily tasks are to process incoming requests and update the inventory of the Warehouse. Requests only include buying, selling, unpacking, and packing containers. The warehouse includes goods and containers and has unlimited space. A container may contain goods or other containers as sub-containers.

The exact format of the requests is given below.

  • BUY <CONTAINER_DESCRIPTION>
  • SELL <CONTAINER_ID>
  • UNPACK <CONTAINER_ID>
  • PACK <CONTAINER_DESCRIPTION>

Each container which is not inside any other container is uniquely identified by a positive integer ID. Assigning IDs to containers is done sequentially and started from 1ドル$. An ID is valid if and only if its container exists in the warehouse, otherwise it is invalid.

A container description is enclosed in parentheses and lists the contents, which can be either goods or sub-containers. A good is identified exclusively by its name, which consists of non-case-sensitive English letters. Multiple units of a good may be available. To denote quantities, place a positive integer ‘N’ before or after the good name (separated by one whitespace), where N$ < 100$ is the number of the good. For example, ((tomato, potato), 4 celery, (wood, (silk 3, banana 2))) describes a container with four units of celery and two sub-containers.

The description of each request is as follows:

  • BUY: A new container is transferred into the warehouse and an ID is assigned to it.
  • SELL: An existing container with the given ID is ship out and its ID becomes invalid.
  • UNPACK: All goods and sub-containers are extracted from the container and added to the warehouse. Moreover, the sub-containers become new containers and get their own ID. The assignment of IDs to the new containers is based on the order of their appearance in the container description (from left to right). For instance, considering the following two lines as the first requests, results in adding one unit of celery and adding three containers with IDs 2ドル,ドル 3ドル,ドル and 4ドル$ to the warehouse and ID 1ドル$ becomes invalid.
BUY (celery , (Banana), (Celery), (celery))
UNPACK 1
  • PACK: Goods specified in a PACK request are grouped into a new container, which is then assigned the next available ID.

Mike and Sulley process the requests in the order they are received. Any request with an invalid container ID must be discarded. Moreover, for PACK request they need to check if there exists enough units of each good in the warehouse.

Roz, the agent of Monster Inc. has told Mike once ”I’m watching you, Wazowski. Always watching. Always.”, She rolled her desk into their office and asked for requests and reports. She is looking for every detail. She is reviewing each request and might ask a few questions. Her questions might be each of the following types:

  • ? COUNT <good>: How many units of the given good exist outside of containers?
  • ? CONTAINS <good>: How many containers with ID have the given good, i.e. the good is in the container or there is a recursive sub-container which contains that good. ? MIN <good>: At least how many containers should be unpacked to reach one unit of the good. If it is impossible, the answer should be $-1$.

Mike and Sully are expected to answer these queries using just one integer.

Before helping Mike and Sully, read samples carefully.

입력

The input consists of $n$ requests or queries from Roz while she is reviewing (1ドル \le n \le 5000$); each appears in a separated line. The name of each good is limited to 100ドル$ characters. Each container description might have at most 5000ドル$ characters and the input size is less than 10ドル^6$ characters.

출력

Each line of the report is associated with a request or Roz’s questions. After each BUY, SELL, PACK, UNPACK request, you should print OK, if the request is not discarded. Otherwise, print DISCARD. If the request is UNPACK, after printing OK, you should print the number of containers added to the warehouse (read samples for more details). For each Roz’s query, print just one integer in a line.

제한

예제 입력 1

BUY (10 apple, 10 carrot, 10 banana, ())
UNPACK 1
UNPACK 2
PACK (3 apple, (5 cArrot, 2 banana))
PACK (3 apple, (5 carrOt, 1 banana))
PACK (5 apple, (3 banana))
? MIN apple
? MIN CaRRoT
? CONTAINS apple

예제 출력 1

OK
OK, 1 container added.
OK, No containers added.
OK
OK
DISCARD
0
2
2

예제 입력 2

BUY (apple, (banana, 3 carrot))
BUY ((banana, apple), (banana, carrot))
? MIN apple
UNPACK 1
? COUNT apple
? COUNT carrot
? CONTAINS banana

예제 출력 2

OK
OK
1
OK, 1 container added.
1
0
2

예제 입력 3

BUY ((duck 2, carrot), 1 celery)
? MIN duck
? MIN carrot
? MIN celery
? MIN test
SELL 10
PACK (celery)
UNPACK 1
UNPACK 1
PACK (celery)
? COUNT celery
? COUNT carrot
? CONTAINS celery
? CONTAINS carrot
BUY ((duck 8, carrot), ((7 duck), celery))
UNPACK 4
UNPACK 5
UNPACK 6
? COUNT DUCK
? MIN duck

예제 출력 3

OK
2
2
1
-1
DISCARD
DISCARD
OK, 1 container added.
DISCARD
OK
0
0
1
1
OK
OK, 2 containers added.
OK, No containers added.
OK, 1 container added.
8
0

힌트

출처

ICPC > Regionals > Asia West Continent > Iran > 2023 ICPC Asia Tehran Regional Contest K번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /