Problem H
Dropping Ball
You are given a board with
In each cell of the board, there is a diagonal wall. The wall either runs from top-left corner to bottom-right corner, or runs from top-right corner to bottom-left corner.
![\includegraphics[width=0.2\textwidth ]{initial.png}](/problems/droppingball/file/statement/en/img-0001.png)
If you drop a ball at some column at the first row, the ball will fall downward due to gravity. Since the ball cannot go through the diagonal walls, it will travel inside the board, and the ball can have one of the following outcomes:
-
The ball is stuck inside the board.
-
The ball exits the board from the left edge.
-
The ball exits the board from the right edge.
-
The ball exits the board at the bottom edge.
For example, if we drop a ball at column
![\includegraphics[width=0.2\textwidth ]{query1.png}](/problems/droppingball/file/statement/en/img-0002.png)
If we drop a ball at column
![\includegraphics[width=0.2\textwidth ]{query2.png}](/problems/droppingball/file/statement/en/img-0003.png)
In this problem, we are interested in the question: “If we
drop the ball at the top of column
Those questions look easy but there is also a twist. We can
flip the wall to change the direction from direction ‘\’ to
direction ‘/’ or vice versa. For example, if we flip the wall
at cell
![\includegraphics[width=0.2\textwidth ]{query3.png}](/problems/droppingball/file/statement/en/img-0004.png)
After that, if we drop the ball again at column
![\includegraphics[width=0.2\textwidth ]{query4.png}](/problems/droppingball/file/statement/en/img-0005.png)
Given
Input
-
The input starts with
positive integers , and . -
The next
lines, each contains a string of length describes the initial board. The -th character in the -th line indicate the wall direction in cell .-
‘\’ indicates top-left to bottom-right direction,
-
‘/’ indicates top-right to bottom-left direction.
-
-
The next
lines describe queries. Each query belongs to one of the two types:-
- flip the wall at cell . -
- drop the ball at column .
-
Output
For each query of type
-
Print
if the ball can not exit at the bottom edge, -
Otherwise, print the index of the column where the ball exits.
Sample Input 1 | Sample Output 1 |
---|---|
4 4 7 \\\\ //// \\\\ /\\\ 2 4 2 1 1 4 2 2 1 2 2 1 4 4 2 2 |
-1 3 1 4 -1 |