Problem F
Matrix Fraud
For the purposes of this problem: A matrix is a binary
matrix if all its entries are
-
Every row has at least one
. -
Every column has at least one
. -
All
s in each row are contiguous. -
For row
, if is the leftmost column that has a entry and is the rightmost column that has a entry, then it must satisfy and for .
Detecting banded binary matrices is an important method used in various fields like biology, paleontology, and linguistics to unearth clusters in data sets. Unfortunately, a group called the Immoral Cartel of Pure Cozeners (ICPC) has decided to do the unthinkable: manipulate data! The ICPC wishes to present their groundbreaking scientific results, but the scientific community will not take their results seriously because their matrices may not be banded. To have publishable results, they want to toggle some cells such that their data is a banded binary matrix.
The ICPC gives you its raw data, represented as a binary
matrix. They want to toggle some cells (meaning, change a
Input
The first line of input contains two integers
Each of the next
Output
Output a single integer, which is the minimum number of entries in the matrix to toggle to make the input matrix a binary banded matrix.
Sample Input 1 | Sample Output 1 |
---|---|
3 4 1100 0101 0011 |
1 |