CF1695A.Subrectangle Guess
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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≤i≤n) row and j-th (1≤j≤m) column by (i,j) and the number there by aij.
Michael starts by saying two numbers h (1≤h≤n) and w (1≤w≤m). Then Joe picks any h×w subrectangle of the board (without Michael seeing).
Formally, an h×w subrectangle starts at some square (a,b) where 1≤a≤n−h+1 and 1≤b≤m−w+1. It contains all squares (i,j) for a≤i≤a+h−1 and b≤j≤b+w−1.
Possible move by Joe if Michael says 3×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⋅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.
迈克尔和乔正在玩一个游戏。游戏在一个 n 行 m 列的网格上进行,网格中填入了互不相同的整数。我们用 (i,j) 表示第 i 行(1≤i≤n)第 j 列(1≤j≤m)的格子,其中的数字记为 aij。
迈克尔首先说出两个数 h(1≤h≤n)和 w(1≤w≤m)。接着,乔在不被迈克尔看到的情况下,任意选择一个 h×w 的子矩形。
形式化地说,一个 h×w 子矩形起始于某个格子 (a,b),其中 1≤a≤n−h+1 且 1≤b≤m−w+1;它包含所有满足 a≤i≤a+h−1 且 b≤j≤b+w−1 的格子 (i,j)。
若迈克尔说 3×2,乔的一种可能操作(该子矩形的最大值为 15)。
最后,迈克尔必须猜出该子矩形中的最大数。若他猜对了,就算获胜。
由于迈克尔不喜欢大数,他希望所选子矩形的面积(即 h⋅w)尽可能小,同时仍能保证自己必胜(即无论乔如何选择子矩形,他都能猜对最大值)。请帮助迈克尔找出这个最小可能的面积。
可以证明:迈克尔总能找到一组 h,w,使得他能够确保获胜。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤20). Description of the test cases follows.
The first line of each test case contains two integers n and m (1≤n,m≤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 aij (−109≤aij≤109) — the element in the cell (i,j).
It is guaranteed that all the numbers are distinct (that is, if ai1j1=ai2j2, then i1=i2,j1=j2).
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤20)。随后是测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(1≤n,m≤40)—— 表示网格的大小。
接下来的 n 行,每行包含 m 个整数。第 i 行的第 j 个整数为 aij(−109≤aij≤109)—— 表示位于单元格 (i,j) 中的元素。
保证所有数字互不相同(即若 ai1j1=ai2j2,则必有 i1=i2 且 j1=j2)。
输出格式
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.
对于每个测试用例,输出一个正整数——在保证迈克尔必胜的前提下,该子矩形可能的最小面积。
输入输出样例
输入#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
输出#1
1 9 4
说明/提示
In the first test case, the grid is 1×1, so the only possible choice for h,w is h=1,w=1, giving an area of h⋅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⋅w≤8 doesn't.
在第一个测试用例中,网格大小为 1×1,因此 h,w 的唯一可能取值是 h=1,w=1,对应面积为 h⋅w=1。
第二个测试用例对应的网格已在题目陈述中绘出。可以证明:当 h=3,w=3 时,Michael 能够确保获胜;而对任意满足 h⋅w≤8 的选择,他均无法确保获胜。
输入解题思路,AI测评打分。不知道怎么写?