황소개발자
백준 2468 파이썬 python : 안전 영역 @@황소처럼 우직하게@@ 시간 재면서 풀자 본문
반응형
10분컷
import sys
input = sys.stdin.readline
n = int(input())
mat = []
for i in range(n):
mat.append(list(map(int, input().split())))
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
def bfs(sy, sx, visited, cnt, wh):
visited[sy][sx] = 1
q = []
q.append([sy, sx])
while q:
y, x = q.pop(0)
for i in range(4):
ny = y + dy[i]
nx = x + dx[i]
if 0 <= nx < n and 0 <= ny < n and visited[ny][nx] == 0 and mat[ny][nx] > wh:
visited[ny][nx] = cnt
q.append([ny, nx])
ans = 1
wh = 1
while True:
cnt = 1
visited = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
for j in range(n):
if visited[i][j] == 0 and mat[i][j] > wh:
bfs(i, j, visited, cnt, wh)
cnt += 1
if cnt - 1 == 0:
break
ans = max(ans, cnt - 1)
wh += 1
print(ans)
반응형
'백준 문제 풀이' 카테고리의 다른 글
백준 C 9095 :: 1, 2, 3 더하기 @@황소처럼 우직하게@@ 다시 가자 (3) | 2020.05.28 |
---|---|
소마 11기 코테 2차 :: 소프트웨어 마에스트로 11기 코딩 테스트 2차 후기. (2) | 2020.05.01 |
백준 6359 파이썬 python : 만취한 성범 @@황소처럼 우직하게@@ 뭐냐.. 이게 왜 dp여 그냥 구현이지 (0) | 2020.04.26 |
백준 1937 파이썬 python : 욕심쟁이 판다 @@황소처럼 우직하게@@ dp는 썻던걸 또 써먹는 알고리즘입니다. (0) | 2020.04.25 |
백준 1309 파이썬 python : 동물원 @@황소처럼 우직하게@@ 자 떠어나자 동해 바다로~ (0) | 2020.04.25 |
Comments