MetaOA #1
Falling Figure — Min Obstacles to Remove
Estimated MediumJudge-ready
Topics (AI-labelled)SimulationIn-place Arrays
In the grid, * forms a non-empty 4-connected shape, # is an obstacle, and - is an empty cell. The shape does not rotate or deform; it only moves down as a whole, one cell at a time, until at least one of its cells reaches the bottom row. Find the minimum number of distinct obstacles that must be removed. The original site's example does not satisfy the connectivity constraint, so this site wrote a new example that follows the rules.
Input
The first line contains the number of rows R and the number of columns C (1..100); the next R lines are strings of length C containing only *, #, and -. The shape is guaranteed to be non-empty and 4-connected.
Output
Output the answer as described; separate multiple results with spaces in order, and output an empty line for an empty array.
Example 1
Input:
3 2
**
-#
--
Output:
1
Example 2
Input:
1 1
*
Output:
0
Example 3
Input:
3 3
***
###
###
Output:
6
Example notes
Example 1: the shape moves down two rows, and the upper-right asterisk must pass through the obstacle on the right; after removing that one obstacle, both asterisks can reach the bottom row, so the answer is 1.
Editorial
Loading solution…