#C2065. Minimum Cell Changes to Ensure Ones
Minimum Cell Changes to Ensure Ones
Minimum Cell Changes to Ensure Ones
You are given a grid of size (n \times m) containing only 0s and 1s. Your task is to determine the minimum number of cell changes (from 0 to 1) required so that every row and every column contains at least one 1. In other words, after performing the changes, for every row (i) and every column (j), there must exist at least one cell such that (grid[i][j] = 1). If it is impossible to achieve this condition, output (-1).
inputFormat
The first line contains two integers (n) and (m) (the number of rows and columns, respectively). Each of the next (n) lines contains (m) integers (either 0 or 1) representing the grid.
outputFormat
Print a single integer representing the minimum number of cell changes required so that each row and column has at least one 1. If it is impossible, print (-1).## sample
3 3
0 0 0
0 0 0
0 0 0
3