#include <bits/stdc++.h>
using namespace std;
int n, m, h;
int visited[105][105][105];
int ar[105][105][105];
int xdir[6] = {1, -1, 0, 0, 0, 0};
int ydir[6] = {0, 0, 1, -1, 0, 0};
int zdir[6] = {0, 0, 0, 0, 1, -1};
struct point
{
int x, y, z, lvl;
};
void push(queue<point> &q, int a, int b, int c, int d)
{
if(a<0 || a>=n || b<0 || b>=m || c<0 || c>=h) return;
if(visited[a][b][c]) return;
if(ar[a][b][c] == -1) return;
visited[a][b][c] = 1;
q.push({a, b, c, d});
}
int bfs()
{
queue<point> q;
int ans = 0;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
for(int k = 0; k < h; k++)
{
if(ar[i][j][k] == 1)
push(q, i, j, k, 0);
}
}
}
while(!q.empty())
{
ans = max(ans, q.front().lvl);
int x=q.front().x, y=q.front().y, z=q.front().z;
int lvl = q.front().lvl;
q.pop();
for(int i = 0; i < 6; i++)
push(q, x+xdir[i], y+ydir[i], z+zdir[i], lvl+1);
}
return ans;
}
int main()
{
cin.tie(NULL); cout.tie(NULL);
ios_base::sync_with_stdio(false);
cin >> m >> n >> h;
for(int i = 0; i < h; i++)
{
for(int j = 0; j < n; j++)
{
for(int k = 0; k < m; k++)
{
cin >> ar[j][k][i];
}
}
}
int ans = bfs();
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
for(int k = 0; k < h; k++)
{
if(ar[i][j][k] == 0 && visited[i][j][k] == 0)
{
cout << -1;
return 0;
}
}
}
}cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
3 ms |
1236 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2684 KB |
Output is correct |
2 |
Correct |
4 ms |
1620 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
4 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
5332 KB |
Output is correct |
2 |
Correct |
15 ms |
6324 KB |
Output is correct |
3 |
Correct |
24 ms |
6612 KB |
Output is correct |
4 |
Correct |
25 ms |
6212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2772 KB |
Output is correct |
2 |
Correct |
5 ms |
1876 KB |
Output is correct |
3 |
Correct |
21 ms |
6360 KB |
Output is correct |
4 |
Correct |
7 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
4188 KB |
Output is correct |
2 |
Correct |
16 ms |
3516 KB |
Output is correct |
3 |
Correct |
28 ms |
4752 KB |
Output is correct |
4 |
Correct |
8 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
7708 KB |
Output is correct |
2 |
Correct |
25 ms |
6348 KB |
Output is correct |
3 |
Correct |
78 ms |
9156 KB |
Output is correct |
4 |
Correct |
9 ms |
5332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
8824 KB |
Output is correct |
2 |
Correct |
82 ms |
8284 KB |
Output is correct |
3 |
Correct |
76 ms |
8424 KB |
Output is correct |
4 |
Correct |
78 ms |
9120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
11472 KB |
Output is correct |
2 |
Correct |
103 ms |
11060 KB |
Output is correct |
3 |
Correct |
106 ms |
11348 KB |
Output is correct |
4 |
Correct |
68 ms |
11528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
11780 KB |
Output is correct |
2 |
Correct |
38 ms |
8356 KB |
Output is correct |
3 |
Correct |
133 ms |
13036 KB |
Output is correct |
4 |
Correct |
29 ms |
8192 KB |
Output is correct |