#K36022. Robot Vacuum Simulator
Robot Vacuum Simulator
Robot Vacuum Simulator
You are given a rectangular grid with n rows and m columns. A robot vacuum starts at the top-left corner (coordinate (0,0)). It is provided with a sequence of k commands. Each command consists of a direction and a number of steps to move in that direction. The directions can be:
- up: move one cell upward (decrease row by 1).
- down: move one cell downward (increase row by 1).
- left: move one cell to the left (decrease column by 1).
- right: move one cell to the right (increase column by 1).
The grid also contains b barriers located at specific coordinates. The robot cannot pass through these barriers. The robot will follow the commands step by step. If at any point the robot moves out of the grid boundaries or steps onto a barrier, the operation should immediately stop and output blocked
. If all commands are executed successfully without any such incident, output success
.
The grid boundaries are given by \(0 \leq r < n\) and \(0 \leq c < m\), where \(r\) is the row and \(c\) is the column index.
inputFormat
The input is read from standard input (stdin
) and has the following format:
n m k command_1 steps_1 command_2 steps_2 ... command_k steps_k b barrier_row_1 barrier_col_1 barrier_row_2 barrier_col_2 ... barrier_row_b barrier_col_b
Here, n and m are the number of rows and columns of the grid respectively, and k is the number of commands. Each command is a string (up
, down
, left
, or right
) followed by an integer indicating the number of steps in that direction. b denotes the number of barriers, followed by b lines each containing two integers representing the coordinates of a barrier.
outputFormat
The output should be printed to standard output (stdout
). It is a single word, either success
if the robot completes all commands without issues, or blocked
if the robot either hits a barrier or moves outside the grid bounds.
5 5 3
right 3
down 2
left 1
0
success