Codeforces Round 841 (Div. 2) and Divide by Zero 2022
D
Valiant's New Map
Codeforces
1700
原题
← CE →
翻译中…

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 \times m$ cellular grid. Each cell $(i, j)$ ($1 \le i \le n$; $1 \le j \le m$) of the grid is occupied by a cuboid building of height $a_{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 \times l$ square inside Mumbai, such that each building inside the square has a height of at least $l$.

翻译中…

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

翻译中…

Input

翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

样例

Input #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
Output #1
2
1
1
3
InputCopy OutputCopy
题目信息
题号
1731D
时间限制
2 s
内存限制
256 MB
标签
二分
暴力
数据结构
动态规划
双指针

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