Highest Mountain
면접 대비시간 제한1초메모리 제한1024 MB
높이 격자가 주어질 때, 인접한 네 칸 중 더 낮은 칸이 있는 칸을 산지로 표시하고, 서로 인접한 산지들을 하나의 산으로 묶어 각 산의 최대 높이와 최소 높이의 차이 중 가장 큰 값을 구한다. 산이 없으면 -1을 출력한다.
문제
You are given a rectangular grid representing a map. Each square in the grid contains an integer, 0 ≤ H ≤ 10000, giving the height (altitude) of the square. A square is 'mountainous' if one or more of the four directly adjacent (north, east, south, or west) squares is at a lower elevation. A set of at least two directly adjacent 'mountainous' squares together form a single 'mountain'.
The height of any 'mountain' is the difference between the the greatest height and the least height of all the squares that comprise the mountain. Your task is to find the highest mountain on a given grid.
입력
- Line 1: two integers: R, C (1 ≤ R ≤ 100, the number of rows in the grid, 1 ≤ C ≤ 100, the number of columns in the grid).
- Lines 2..R+1: C single-space separated integers denoting mountain heights
출력
The output is a single line that contains one integer that is the height of the highest mountain on the grid or -1 if no mountain exists.