작성
·
258
0
import sys
from collections import deque
sys.stdin = open("input.txt", 'r')
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
n = int(input())
board = [list(map(int, input().split())) for _ in range(n)]
res = 0
dq = deque()
for h in range(100):
ch = [[0]*n for _ in range(n)]
cnt = 0
for i in range(n):
for j in range(n):
if board[i][j] > h:
dq.append((i, j))
ch[i][j] = 1
while dq:
tmp = dq.popleft()
for k in range(4):
x = tmp[0]+dx[k]
y = tmp[1]+dy[k]
if 0 <= x < n and 0 <= y < n and ch[x][y] == 0 and board[x][y] > h:
ch[x][y] = 1
dq.append((x, y))
cnt += 1
res = max(res, cnt)
if cnt == 0:
break
print(res)