#BS0000446. Bản đồ mới của Valiant (Valiant's New Map)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bản đồ mới của Valiant (Valiant's New Map)
Valiant's New Map
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
DbZ Games is designing a map named Panvel for Valiant, inspired by Mumbai. The city is represented by a grid with rows and columns. The building at row , column has height .
The studio wants a square region of consecutive rows and consecutive columns. Every building in this region must have height at least . The square is aligned with the rows and columns of the grid.
Find the greatest side length of a valid square.
Input
- The first line contains integers , the row and column counts.
- Each of the next lines contains integers , the building heights in row .
Output
Print one integer, the maximum side length of a valid square.
Subtasks
- Subtask 1 (20 points): ; ; for all , .
- Subtask 2 (30 points): ; ; for all , .
- Subtask 3 (50 points): ; ; for all , .
Examples
Example 1
Input
2 2
2 3
4 5
Output
2
Explanation
The whole grid has side 2 and every height is at least 2. A larger square is impossible with two rows.
Example 2
Input
1 3
1 2 3
Output
1
Explanation
There is only one row, so the side is at most 1. The first cell has height 1 and qualifies.
Example 3
Input
2 3
4 4 3
2 1 4
Output
1
Explanation
Both squares of side 2 contain the height-1 cell in row 2, column 2. Neither qualifies; every cell qualifies for side 1.
Example 4
Input
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
3
Explanation
Choose rows 1–3 and columns 2–4: the nine heights are 9, 4, 6, 9, 5, 8, 42, 32, 8, with minimum 4. Every side-4 square starting in column 1 or 2 contains the height-1 cell at row 4 column 2; starting in column 3 includes the height-1 cell at row 3 column 6. Side 5 is also impossible since it contains a side-4 square.