Matrix Fraud
Time limit1sMemory limit2048 MB
Find the fewest cell toggles that make every row a contiguous block of 1s, every column contain a 1, and both row endpoints never move left.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Prefix sum, Matrix
- Solved
- No attempts yet
Definitions
For this problem, a matrix is a binary matrix if every entry is or . A binary matrix is a banded binary matrix if it satisfies the following properties:
- Every row has at least one .
- Every column has at least one .
- All s in each row are contiguous.
- For row , let be the leftmost column with a entry and the rightmost. Then and .
Problem
The Immoral Cartel of Pure Cozeners (ICPC) wants to publish results from a data set, but its matrix may not be banded. The group toggles cells, changing a to a or a to a , so that the matrix becomes a banded binary matrix. Find the fewest toggles needed to turn the given matrix into a banded binary matrix.
Input
The first line contains two integers and (), the number of rows and columns. Each of the next lines contains a binary string of length , which is a row of the matrix.
Output
Print a single integer, the minimum number of entries to toggle to make the matrix a banded binary matrix.