아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Highest Mountain

면접 대비

시간 제한1초메모리 제한1024 MB

요약
높이 격자가 주어질 때, 인접한 네 칸 중 더 낮은 칸이 있는 칸을 산지로 표시하고, 서로 인접한 산지들을 하나의 산으로 묶어 각 산의 최대 높이와 최소 높이의 차이 중 가장 큰 값을 구한다. 산이 없으면 -1을 출력한다.
난이도

보통10점 중 5점

유형
DFS, BFS, 구현, 배열
정답자
아직 제출이 없습니다

문제

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.

예제1

  1. 예제 1

    입력
    6 8
    1 3 3 4 4 4 1 1
    1 4 2 1 1 1 1 1
    1 5 3 1 1 4 1 1
    1 6 5 3 1 7 4 1
    1 3 3 3 1 4 5 1
    1 3 3 1 1 1 1 1
    
    예상 출력
    4