AGC033 A - Darker and Darker
提出
code: python
from collections import deque
h, w = map(int,input().split())
black = []
for i in range(h):
for j in range(w):
def dfs(q):
nowi, nowj = q.popleft()
# 多点スタート
for i in black:
dfs(q)
解答
code: python
from collections import deque
H, W = map(int, input().split())
dist = [-1 * W for _ in range(H)] black_cells = deque()
for h in range(H):
for w in range(W):
black_cells.append((h, w))
while black_cells:
h, w = black_cells.popleft()
for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
new_h = h + dy
new_w = w + dx
if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
continue
black_cells.append((new_h, new_w))
ans = -1
for i in range(H):
for j in range(W):
if (res > ans):
ans = res
print(ans)
テーマ
メモ