-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7569.py
More file actions
37 lines (33 loc) · 875 Bytes
/
7569.py
File metadata and controls
37 lines (33 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from collections import deque
m, n, h = map(int, input().split())
graph = []
queue = deque([])
for i in range(h):
tmp = []
for j in range(n):
tmp.append(list(map(int, input().split())))
for k in range(m):
if tmp[k][j] == 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)