[Solution] Subrectangle Guess Codeforces Solution | Codeforces Problem Solution 2022
A. Subrectangle Guess
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.
Solution Click Below:- CLICK HERE
Input
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).
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.
No comments:
Post a Comment