Skip to content

Commit

Permalink
daily
Browse files Browse the repository at this point in the history
  • Loading branch information
runnz121 committed Jan 8, 2022
1 parent fcf2b3e commit f162883
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions 7569.py
@@ -0,0 +1,39 @@
import sys
from collections import deque

m, n, h = map(int, input().split()) # mn크기, h상자수
graph = []
queue = deque([])

for i in range(h):
tmp = []
for j in range(n):
tmp.append(list(map(int, sys.stdin.readline().split())))
for k in range(m):
if tmp[j][k] == 1:
queue.append([i, j, k])
graph.append(tmp)

dx = [-1, 1, 0, 0, 0, 0]
dy = [0, 0, 1, -1, 0, 0]
dz = [0, 0, 0, 0, 1, -1]
while (queue):
x, y, z = queue.popleft()

for i in range(6):
a = x + dx[i]
b = y + dy[i]
c = z + dz[i]
if 0 <= a < h and 0 <= b < n and 0 <= c < m and graph[a][b][c] == 0:
queue.append([a, b, c])
graph[a][b][c] = graph[x][y][z] + 1

day = 0
for i in graph:
for j in i:
for k in j:
if k == 0:
print(-1)
exit(0)
day = max(day, max(j))
print(day - 1)

0 comments on commit f162883

Please sign in to comment.