#K33262. Maximum Conversion of Subgrid Ones
Maximum Conversion of Subgrid Ones
Maximum Conversion of Subgrid Ones
Given an (R \times C) grid consisting of 0's and 1's, you are allowed to convert a full 2(\times)2 subgrid of ones into zeros. In each operation, if a 2(\times)2 block contains only ones, you can change all four entries to 0, and this conversion counts as 4 ones being turned into zeros. Your task is to determine the maximum number of ones that can be converted by applying these operations greedily from top-left to bottom-right.
Formally, let (A) be a matrix where (A_{ij} \in {0,1}). For every 2(\times)2 submatrix (\begin{pmatrix}A_{ij} & A_{i,j+1}\ A_{i+1,j} & A_{i+1,j+1}\end{pmatrix}) that has all entries equal to 1, you turn them into zeros and add 4 to your total count. Compute the maximum total count achievable by performing these operations.
inputFormat
The first line contains two integers (R) and (C) representing the number of rows and columns. Each of the following (R) lines contains (C) integers (each either 0 or 1) separated by spaces that represent the grid.
outputFormat
Output a single integer representing the maximum number of ones that can be converted to zeros.## sample
3 3
1 1 1
1 1 1
1 1 1
4