| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 10 초 (추가 시간 없음) | 1024 MB | 185 | 99 | 82 | 55.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:
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.
8 DdaacCAA
0
14 aabcdDCBdDAbBA
1