#C11934. Warehouse Inventory Management
Warehouse Inventory Management
Warehouse Inventory Management
You are given a warehouse represented as a grid with (n) rows and (m) columns. Each cell initially contains an item located at its own coordinate ((i, j)). You will be given (q) commands in the form MOVE i j DIRECTION
where DIRECTION can be one of: UP
, DOWN
, LEFT
, or RIGHT
.
For each command, if the move is valid (i.e. it does not cause the item to leave the grid), update the item’s position; otherwise, mark the item as Invalid Move
. Note that each command applies to the item originally at that position, regardless of any previous moves. Your task is to process all commands and output the final positions of all items in the warehouse in row-major order. For each cell, if the item has been moved successfully, output its new coordinates in the format ((x, y)); otherwise, output Invalid Move
.
inputFormat
The input is provided via stdin in the following format:
(n) (m) (q)
command_1
command_2
...
command_q
Here, (n) and (m) are integers specifying the number of rows and columns respectively, (q) is the number of move commands, and each command is a string in the format MOVE i j DIRECTION
.
outputFormat
For each cell in the warehouse (processed in row-major order), output a line in the following format:
(i, j) -> (x, y) if the move was valid
(i, j) -> Invalid Move if the move was invalid
Here, ((i, j)) represents the initial position of the item and ((x, y)) is its final position if the move was successful.## sample
4 4 5
MOVE 2 2 UP
MOVE 3 2 DOWN
MOVE 2 1 LEFT
MOVE 1 1 RIGHT
MOVE 4 4 UP
(1, 1) -> (1, 2)
(1, 2) -> (1, 2)
(1, 3) -> (1, 3)
(1, 4) -> (1, 4)
(2, 1) -> Invalid Move
(2, 2) -> (1, 2)
(2, 3) -> (2, 3)
(2, 4) -> (2, 4)
(3, 1) -> (3, 1)
(3, 2) -> (4, 2)
(3, 3) -> (3, 3)
(3, 4) -> (3, 4)
(4, 1) -> (4, 1)
(4, 2) -> (4, 2)
(4, 3) -> (4, 3)
(4, 4) -> (3, 4)
</p>