Submatrices in a matrix

2.1

10 votes
Implementation, Math Basic, Basics of Implementation, C++, Basic Math, Math, Game Theory
Problem

Alice and Bob want to play a game. They have a matrix N×M that should be only from 0 to 1.
Alice makes an arbitrary (possibly zero) number of complete horizontal cuts of the matrices and Bob makes an arbitrary (possibly zero) number of the upper vertical cuts. After making all the cuts, the matrix is decomposed into a number of rectangular submatrices. Since Bob is very fond of a matrix of 1, he wants the number of whole submatrices that consist exclusively of units, to be as large as possible after all the cuts. Alice wants to keep this amount as small as possible.

Note that they are not interested in what size the submatrices will be, their focus is on the number.

To be fair, John will ask Alice and Bob individually and independently where the cuts are to be made and then he will make the cuts instead.

Based on the provided size of the matrix and the matrix itself, write a program that prints the number of submatrices that are formed after all the cuts considering the optimal actions of Alice and Bob.

Input format

  • The first line contains two integers N and M denoting the height and width of the matrix.
  • Each of the next N lines contains M characters that can be only 0 and 1.

Output format

Print a single number denoting the answer to the problem.

Constraints

2N,M1000

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In first test Bob make 3 vertical cuts, Alice - 0 horizontal cuts.

Editor Image

?