#K46642. Gravity Simulation on a Grid
Gravity Simulation on a Grid
Gravity Simulation on a Grid
You are given a 2D grid with .
representing empty space and #
representing obstacles. A player starts at a given coordinate (start_x, start_y) in the grid. The player is affected by gravity and will move downward (i.e. increasing the row index) until either reaching the grid boundary or encountering an obstacle immediately below.
Your task is to determine the final position of the player after gravity is applied. The player starts at the given starting position, and if the cell directly below is empty (.
), the player falls. This repeats until the cell below is not empty or the player reaches the bottom row.
Note: The coordinate system is 0-indexed, meaning the top left cell of the grid is (0, 0).
inputFormat
The first line contains two integers R and C where R is the number of rows and C is the number of columns in the grid.
The following R lines each contain a string of length C that represents a row of the grid. Each character is either .
(empty space) or #
(obstacle).
The last line contains two integers start_x and start_y representing the starting row and column of the player.
outputFormat
Output two integers separated by a space, representing the final row and column position of the player after gravity is applied.
## sample4 4
....
..#.
....
####
1 0
2 0
</p>