Even sum in a matrix

2.9

16 votes
Math Basic, Bitmask, Basic Programming, Bit manipulation, Basics of Bit Manipulation, Bit Manipulation, Math
Problem

You are given a matrix A containing N×M elements. You are required to find the number of rectangular submatrices of this matrix such that the sum of the elements in each such submatrix is even.

Input format

  • The first line of input given two numbers N and M denoting the dimensions of the matrix.
  • The next N lines contain space-separated M numbers.

Output format

Print a number denoting the number of rectangular submatrices, the sum of the elements of each is even.

Constraints

1N,M2000

1Ai,j1091iN,1jM

 

Time Limit: 2.5
Memory Limit: 256
Source Limit:
Explanation

The following sub-matrices are suitable for us:

(2)(4),(6),(1,2,3)

(1,24,5)(2,35,6)

Count submatrices = 6.

Editor Image

?