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

30614번 - Port Robot 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
10 초 (추가 시간 없음) 1024 MB185998255.782%

문제

You are developing a robot that helps in storing containers that have arrived at ports before sending them to ships. These robots are responsible for handling these containers using limited space. Specifically, the space can fit multiple containers one over the other, but not side by side, as depicted in the figure.

While operating, the robot performs two actions:

  1. Putting a container in storage.
  2. Taking a container from storage.

There are 26 types of containers in this port, each one characterized by a letter of the Latin alphabet. Each time an action is performed, the robot logs the type of the container in lowercase when storing a container and in uppercase when taking a container from storage. Your task is to check if the logs produced by a robot indicate stable operation. In stable operation, the logged containers of action type 2 exist in storage and are in the uppermost position. Moreover, in stable operation, we always end with empty storage.

As an example, consider a scenario in which the robot produces the log: 'cdDC'. Here, we have a stable operation of the robot, as the robot initially places 'c' and then 'd' (indicating that 'd' is in the upper position). The robot then takes the first 'd' out and, finally, takes out 'c'. On the other hand, an unstable operation would result from the log: 'cdCD', since the robot cannot take 'c' before taking out 'd'.

입력

The first line contains the length of the log generated by the robot. The second line contains the extracted log of the robot operation.

출력

A single number 0 if the log indicate wrong operation and 1 if the operation is stable.

제한

예제 입력 1

8
DdaacCAA

예제 출력 1

0

예제 입력 2

14
aabcdDCBdDAbBA

예제 출력 2

1

힌트

출처

ICPC > Regionals > Europe > Southeastern European Regional Contest > Greek Collegiate Programming Contest > GRCPC 2023 6번

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

출처

대학교 대회

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

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