Skip to content

Latest commit

 

History

History
56 lines (46 loc) · 1.08 KB

7569.md

File metadata and controls

56 lines (46 loc) · 1.08 KB

7569

Python

# 시간 초과되는지 처음 알았다...
import sys
input = sys.stdin.readline
import sys
from collections import deque

M, N, H = map(int, sys.stdin.readline().split())
boxes = [[list(map(int, sys.stdin.readline().split())) for _ in range(N)] for _ in range(H)]

dx = [-1, 1, 0, 0, 0, 0]
dy = [0, 0, -1, 1, 0, 0]
dh = [0, 0, 0, 0, -1, 1]

q = deque()
for h in range(H):
    for n in range(N):
        for m in range(M):
            if boxes[h][n][m] == 1:
                q.append([h, n, m])

while q:
    h, x, y = q.popleft()
    for d in range(6):
        nh = h + dh[d]
        nx = x + dx[d]
        ny = y + dy[d]
        if 0 <= nh < H and 0 <= nx < N and 0 <= ny < M and boxes[nh][nx][ny] == 0:
            boxes[nh][nx][ny] = boxes[h][x][y] + 1
            q.append([nh, nx, ny])

day = 0
for h in boxes:
    for m in h:
        for n in m:
            if n == 0:
                day = 0
                break
            day = max(day, n)
        else:
            continue
        break
    else:
        continue
    break

print(day-1)