Count The Crosses

0

0 votes
Dynamic Programming, Counting and Arrangements, Algorithms
Problem

You are given a grid of size nm containing only 0s and 1s. A cross is a 'X' like structure formed in the grid when any two sequence of diagonal 1s intersects each other. Find the count of total number of crosses present in the grid. Since the answer can be large, compute it modulo 109+7.

INPUT FORMAT

The first line contains an integer, t - denoting the number of test cases.

The first line of each test case contains two integers n and m - denoting the number of rows, and columns grid has.

The following n lines of each test case contain a string of length m having characters as either '0' or '1'.

It is guaranteed that the sum of nm across all test cases doesn't exceed 107.

OUTPUT FORMAT

For each test case, print the answer modulo 109+7 in a new line.

Constraints

1<=t<=100

1<=n,m<=107 and sum of nm  across all test cases <= 107

Each cell in Grid is either 0 or 1

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation
  • Test case 1: There are three crosses as shown below.

 

  • Test case 2: There is no cross.
Editor Image

?