CF1731D.Valiant's New Map

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Game studio "DbZ Games" wants to introduce another map in their popular game "Valiant". This time, the map named "Panvel" will be based on the city of Mumbai.

Mumbai can be represented as n×mn \times m cellular grid. Each cell (i,j)(i, j) ( 1in1 \le i \le n ; 1jm1 \le j \le m ) of the grid is occupied by a cuboid building of height ai,ja_{i,j} .

This time, DbZ Games want to make a map that has perfect vertical gameplay. That's why they want to choose an l×ll \times l square inside Mumbai, such that each building inside the square has a height of at least ll .

Can you help DbZ Games find such a square of the maximum possible size ll ?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t10001 \leq t \leq 1000 ). Description of the test cases follows.

The first line of each test case contains two positive integers nn and mm ( 1nm1 \le n \le m ; 1nm1061 \leq n \cdot m \leq 10^6 ).

The ii -th of next nn lines contains mm integers ai,1,ai,2,,ai,ma_{i,1}, a_{i,2}, \dots, a_{i,m} ( 1ai,j1061 \leq a_{i,j} \leq 10^6 ) — heights of buildings on the ii -th row.

It's guaranteed that the sum of nmn \cdot m over all test cases doesn't exceed 10610^6 .

输出格式

For each test case, print the maximum side length ll of the square DbZ Games can choose.

输入输出样例

  • 输入#1

    4
    2 2
    2 3
    4 5
    1 3
    1 2 3
    2 3
    4 4 3
    2 1 4
    5 6
    1 9 4 6 5 8
    10 9 5 8 11 6
    24 42 32 8 11 1
    23 1 9 69 13 3
    13 22 60 12 14 17

    输出#1

    2
    1
    1
    3

说明/提示

In the first test case, we can choose the square of side l=2l = 2 (i. e. the whole grid) since the heights of all buildings are greater than or equal to 22 .

In the second test case, we can only choose the side as 11 , so the answer is 11 .

In the third test case, there are no squares of size 22 that have all buildings of height at least 22 , so the answer is 11 .

首页