Skip to content

Commit ed56870

Browse files
committed
solved 7569
1 parent fce56ad commit ed56870

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

7000/7569/7569.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
#define FOR(i, a, b) for (int i = a; i < b; i++)
5+
6+
struct pt{
7+
int x;
8+
int y;
9+
int z;
10+
};
11+
12+
int M, N, H, m[100][100][100], ans = 0, remain = 0;
13+
int dd[6][3] = {{1, 0, 0},{-1, 0, 0},{0, 1, 0},{0, -1, 0},{0, 0, 1},{0, 0, -1}};
14+
queue<pt> q;
15+
16+
17+
int main() {
18+
ios::sync_with_stdio(false); cin.tie(NULL);
19+
cin>>M>>N>>H;
20+
FOR(k, 0, H) FOR(j, 0, N) FOR(i, 0, M){
21+
cin>>m[i][j][k];
22+
if(m[i][j][k] == 1) q.push((pt){i, j, k});
23+
else if(m[i][j][k] == 0) ++remain;
24+
}
25+
26+
while(!q.empty() && remain){
27+
auto t = q.front();
28+
q.pop();
29+
30+
for(auto d: dd){
31+
int x=t.x+d[0], y=t.y+d[1], z=t.z+d[2];
32+
if(x<0||x>=M||y<0||y>=N||z<0||z>=H) continue;
33+
if(m[x][y][z] != 0) continue;
34+
35+
m[x][y][z] = (ans = m[t.x][t.y][t.z]) + 1;
36+
q.push((pt){x, y, z});
37+
--remain;
38+
}
39+
}
40+
41+
if(remain) ans = -1;
42+
cout<<ans;
43+
44+
return 0;
45+
}

0 commit comments

Comments
 (0)