λ¬Έμ
https://www.acmicpc.net/problem/2468
2468λ²: μμ μμ
μ¬λλ°©μ¬μ²μμλ λ§μ λΉκ° λ΄λ¦¬λ μ₯λ§μ² μ λλΉν΄μ λ€μκ³Ό κ°μ μΌμ κ³ννκ³ μλ€. λ¨Όμ μ΄λ€ μ§μμ λμ΄ μ 보λ₯Ό νμ νλ€. κ·Έ λ€μμ κ·Έ μ§μμ λ§μ λΉκ° λ΄λ Έμ λ λ¬Όμ μ κΈ°μ§ μλ
www.acmicpc.net
νμ΄
# λ°±μ€ 2468λ² λ¬Έμ - μμ μμ
from collections import deque
n = int(input())
graph = []
dx, dy = [0,0,-1,1],[1,-1,0,0]
graph = [list(map(int, input().split())) for _ in range(n)]
# 2 <= n ν <= 100
# 1 <= i λμ΄ <= 100
# i = 2 ~ max(graph) - 1
# 1 λΆν° κ·Έλνμ (μ΅λ λμ΄-1)κΉμ§ νμΈνκΈ° μν΄
max_height = []
for i in range(len(graph)):
max_height.append(max(graph[i]))
max_height = max(max_height)
count = 0
def bfs(x, y, k):
count = 1
queue = deque()
queue.append((x,y))
while queue:
x, y = queue.popleft()
visited[x][y] = 1 # λ°©λ¬Έ μ²λ¦¬
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < n and 0 <= ny < n:
if graph[nx][ny] > k and visited[nx][ny] == 0:
queue.append((nx,ny))
count += 1
visited[nx][ny] = 1
return count
res = 0
for k in range(max_height + 1):
visited = [[0]*n for _ in range(n)]
res_cnt = []
for i in range(n):
for j in range(n):
print('I: ', i,' J: ', j, ' K', k)
if graph[i][j] > k and visited[i][j] == 0:
res_cnt.append(bfs(i,j,k))
count = 0
res = max(res, len(res_cnt))
print(res)
'ποΈ Algorithm > π© λ°±μ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
π© [λ°±μ€] [Python] 12865λ²_νλ²ν λ°°λ (0) | 2022.11.09 |
---|---|
π© [λ°±μ€] [Python] 2630λ²_μμ’ μ΄ λ§λ€κΈ° (0) | 2022.11.09 |
π© [λ°±μ€] [Python] 2193λ²_μ΄μΉμ (0) | 2022.11.08 |
π© [λ°±μ€] [Python] [BFS] 7576λ²_ν λ§ν (0) | 2022.11.07 |
π© [λ°±μ€] [Python] [BFS] 1926λ²_κ·Έλ¦Ό (0) | 2022.11.07 |