-
Notifications
You must be signed in to change notification settings - Fork 0
/
안전영역
51 lines (39 loc) · 1002 Bytes
/
안전영역
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 2 23:15:51 2022
@author: kimsubin
"""
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000) #없으면 오류
def dfs(y, x, a):
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]
visited[y][x] = 1
for i in range(4):
nx, ny = dx[i]+x, dy[i]+y
if 0<=nx<n and 0<=ny<n and visited[ny][nx]==0 and arr[ny][nx]>a:
dfs(ny, nx, a)
n = int(input())
arr = [list(map(int, input().split())) for _ in range(n)]
List = []
minn = 0
maxn = 0
for i in range(len(arr)):
List.append(max(arr[i]))
List.append(min(arr[i]))
minn = min(List)
maxn = max(List)
ans = 1
for a in range(minn, maxn+1):
count = 0
visited = [[0]*n for _ in range(n)]
for i in range(n):
for j in range(n):
if arr[i][j]>a and visited[i][j] == 0:
dfs(i, j, a)
count += 1
if count>ans:
ans = count
print(ans)