Codeforces Round 801 (Div. 2) and EPIC Institute of Technology Round
A
Subrectangle Guess
Codeforces
800
原题
←B →
翻译中…

Michael and Joe are playing a game. The game is played on a grid with $n$ rows and $m$ columns, filled with distinct integers. We denote the square on the $i$-th ($1\le i\le n$) row and $j$-th ($1\le j\le m$) column by $(i, j)$ and the number there by $a_{ij}$.

翻译中…

Michael starts by saying two numbers $h$ ($1\le h \le n$) and $w$ ($1\le w \le m$). Then Joe picks any $h\times w$ subrectangle of the board (without Michael seeing).

翻译中…

Formally, an $h\times w$ subrectangle starts at some square $(a,b)$ where $1 \le a \le n-h+1$ and $1 \le b \le m-w+1$. It contains all squares $(i,j)$ for $a \le i \le a+h-1$ and $b \le j \le b+w-1$.

翻译中…

image Possible move by Joe if Michael says $3\times 2$ (with maximum of $15$).

翻译中…

Finally, Michael has to guess the maximum number in the subrectangle. He wins if he gets it right.

翻译中…

Because Michael doesn't like big numbers, he wants the area of the chosen subrectangle (that is, $h \cdot w$), to be as small as possible, while still ensuring that he wins, not depending on Joe's choice. Help Michael out by finding this minimum possible area.

翻译中…

It can be shown that Michael can always choose $h, w$ for which he can ensure that he wins.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 20$). Description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 40$)  — the size of the grid.

翻译中…

Each of the following $n$ lines contains $m$ integers. The $j$-th integer on the $i$-th line is $a_{ij}$ ($-10^9 \le a_{ij} \le 10^9$)  — the element in the cell $(i, j)$.

翻译中…

It is guaranteed that all the numbers are distinct (that is, if $a_{i_1j_1} = a_{i_2j_2}$, then $i_1 = i_2, j_1 = j_2$).

翻译中…

Output

翻译中…

For each test case print a single positive integer  — the minimum possible area the subrectangle can have while still ensuring that Michael can guarantee the victory.

翻译中…

Note

翻译中…

In the first test case, the grid is $1\times 1$, so the only possible choice for $h, w$ is $h = 1, w = 1$, giving an area of $h\cdot w = 1$.

翻译中…

The grid from the second test case is drawn in the statement. It can be shown that with $h = 3, w = 3$ Michael can guarantee the victory and that any choice with $h\cdot w \le 8$ doesn't.

翻译中…

样例

Input #1
3
1 1
3
4 4
2 12 6 10
3 15 16 4
1 13 8 11
14 7 9 5
2 3
-7 5 2
0 8 -3
Output #1
1
9
4
InputCopy OutputCopy
题目信息
题号
1695A
时间限制
1 s
内存限制
256 MB
标签
博弈论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。