https://www.acmicpc.net/problem/2468
n = int(input())
data = [list(map(int,input().split())) for _ in range(n)]
max_value = max(max(data))
temp = [[0]*n for _ in range(n)]
dx = [-1,1,0,0]
dy = [0,0,-1,1]
def dfs(x,y,temp):
q = [(x,y)]
temp[x][y] = 0
while q:
x,y = q.pop()
for i in range(4):
nx,ny = x+dx[i],y+dy[i]
if 0<=nx<n and 0<=ny<n and temp[nx][ny] == 1:
temp[nx][ny] = 0
q.append((nx,ny))
result = 1
for num in range(1,max_value+1):
for i in range(n):
for j in range(n):
if data[i][j] <= num:
temp[i][j] = 0 # 0이면 잠김
else:
temp[i][j] = 1
count = 0
for x in range(n):
for y in range(n):
if temp[x][y] == 1:
dfs(x, y, temp)
count += 1
result = max(count,result)
print(result)
'알고리즘' 카테고리의 다른 글
백준 10026번 : 적록색약(python) (0) | 2021.07.26 |
---|---|
백준 2583번 : 영역 구하기(python) (0) | 2021.07.26 |
백준 2667번 : 단지번호붙이기(python) (0) | 2021.07.26 |
백준 7576번 : 토마토(python) (0) | 2021.07.26 |
백준 1600번 : 말이 되고픈 원숭이(Python) (0) | 2021.06.20 |