AmazonOA #26
Find Max Greyness
Estimated MediumJudge-ready
Topics (AI-labelled)In-place ArraysPrefix & Ranges
The grayness of cell (i,j) equals the total number of 1s minus the total number of 0s in its row and its column; the intersection cell is counted once in the row and once in the column. Find the maximum grayness.
Conventions marked as this site's do not pass themselves off as the source's original limits.
Input
The first line contains n m (both 1..1000), followed by n lines of 01 strings of length m.
Output
Output a single integer, the answer.
Example 1
Input:
3 3
101
001
110
Output:
2
Example 2
Input:
1 1
0
Output:
-2
Example 3
Input:
2 2
11
11
Output:
4
Example notes
Example 1: the first row and the first column each have two 1s and one 0, so the grayness is (2+2)−(1+1)=2. Example 2: the only 0 is counted once in its row and once in its column, so the grayness is −2. Example 3: every row and column has two 1s, so the maximum grayness is 4.
Editorial
Loading solution…