14028 - Max Palindrome Matrix   

Description

If a matrix remains the same when rotated 180 degrees, it is referred to as a "palindrome matrix".

Given an n * m matrix, please output the area of the max (largest) palidrome matrix in it.

 

In sample testcase 1, the max palindrome matrix is:

1 2 3

2 1 2

3 2 1

In sample testcase 2, the max palindrome matrix is:

1 2 3 4

4 3 2 1

 

You may use the following code to get all possible submatrices for Testcases 6 and 7:

// (x1, y1) means the upper left coordinate
// (x2, y2) means the lower right coordinate
for (int x1 = 0; x1 < n; x1++) {
    for (int y1 = 0; y1 < m; y1++) {
        for (int x2 = x1; x2 < n; x2++) {
            for (int y2 = y1; y2 < m; y2++) {
                // your code ...
            }
        }
    }
}

Input

There is an integer T in the first line, representing that you are given T testcases.

In each testcase, the first line contains two integers n and m, and each of the following n lines has m integers, representing the given matrix.

 

1 <= T <= 10, each number in the matrix is between [1, 1e9]

1 <= n, m <= 40

Testcases 1~3: n = 1

Testcases 4, 5: guaranteed that the answer is a square

Testcases 6, 7: no other restriction

 

Output

Print the area of the max palidrome matrix in it.

Don't forget to print '\n' in the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss