#BS0000437. Đường đi có giá trị nhỏ nhất lớn nhất (Path With Maximum Minimum Value)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đường đi có giá trị nhỏ nhất lớn nhất (Path With Maximum Minimum Value)
Path With Maximum Minimum Value
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A table consists of rows and columns, numbered from to and from to , respectively. Cell contains a nonnegative integer .
Starting at , you must reach . In each step, you may move to a cell sharing a side with your current cell in one of the four directions, provided you remain within the table.
The score of a route is the smallest value among all cells visited, including both endpoints. For instance, visiting values gives a score of . When both endpoints coincide, the score equals the value of that cell.
Find the greatest score attainable among all valid routes from the starting cell to the destination.
Input
- The first line contains two integers , the numbers of rows and columns.
- The next lines each contain integers; line lists values of row .
Output
Print one integer: the greatest attainable route score.
Subtasks
- Subtask 1 (20 points): ; for all , .
- Subtask 2 (30 points): ; for all , .
- Subtask 3 (50 points): ; for all , .
Examples
Example 1
Input
3 3
5 4 5
1 2 6
7 4 6
Output
4
Explanation
The route has values , giving score . A score of at least is impossible: the two neighbors of the start have values and .

Example 2
Input
2 6
2 2 1 2 2 2
1 2 2 2 1 2
Output
2
Explanation
Follow the first row to column , go down, move right to column , go up, move right to column , then go down to the destination. Every visited value is . The starting value is , so no higher score is possible.