#C11847. Minimum Moves to Empty Grid
Minimum Moves to Empty Grid
Minimum Moves to Empty Grid
Given an n \times m grid represented as binary strings, where each cell is either '1' (occupied) or '0' (empty), your task is to determine the minimum number of moves required to make the grid empty. In one move, you can select an occupied cell and empty it. Therefore, the answer is the total number of '1's in the grid, which can be expressed as:
$$\text{moves} = \sum_{i=1}^{n}\sum_{j=1}^{m} [\text{grid}_{ij}=1] $$If there are no occupied cells, then the result is 0.
inputFormat
The first line contains two integers n
and m
representing the number of rows and columns respectively. This is followed by n
lines, each containing a binary string of length m
that represents a row of the grid.
outputFormat
Output a single integer — the minimum number of moves required to empty the grid.
## sample3 3
101
011
001
5
</p>