#include <cstdio>
#include <queue>
int m,n,h;
int a[101][101][101];
int depth[101][101][101];
int v[101][101][101];
std::queue<int> x,y,z,d;
void f(int i, int j, int k, int dt){
v[i][j][k]=1;
depth[i][j][k]=dt;
x.push(i);
y.push(j);
z.push(k);
d.push(dt);
}
int main(){
// ("input3.txt","r",stdin);
scanf("%d %d %d",&m,&n,&h);
for (int i=0; i<h; i++) {
for (int j=0; j<n; j++) {
for (int k=0; k<m; k++) {
scanf("%d",&a[i][j][k]);
if(a[i][j][k]==1){
f(i,j,k,0);
}
if(a[i][j][k]==-1){
v[i][j][k]=1;
}
}
}
}
int cx,cy,cz,cd;
while (!x.empty()) {
cx = x.front();
cy = y.front();
cz = z.front();
cd = d.front();
if(cx && !v[cx-1][cy][cz]){
f(cx-1,cy,cz,cd+1);
}
if(cy && !v[cx][cy-1][cz]){
f(cx,cy-1,cz,cd+1);
}
if(cz && !v[cx][cy][cz-1]){
f(cx,cy,cz-1,cd+1);
}
if(cx+1<h && !v[cx+1][cy][cz]){
f(cx+1,cy,cz,cd+1);
}
if(cy+1<n && !v[cx][cy+1][cz]){
f(cx,cy+1,cz,cd+1);
}
if(cz+1<m && !v[cx][cy][cz+1]){
f(cx,cy,cz+1,cd+1);
}
x.pop();
y.pop();
z.pop();
d.pop();
}
int dtmax = 0;
int unvisited = 0;
for (int i=0; i<h; i++) {
for (int j=0; j<n; j++) {
for (int k=0; k<m; k++) {
if(dtmax<depth[i][j][k]) dtmax = depth[i][j][k];
if(v[i][j][k]==0) unvisited = 1;
}
}
}
if(unvisited) printf("-1");
else printf("%d",dtmax);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
13316 KB |
Output is correct |
2 |
Correct |
4 ms |
13316 KB |
Output is correct |
3 |
Correct |
0 ms |
13316 KB |
Output is correct |
4 |
Correct |
0 ms |
13316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
13316 KB |
Output is correct |
2 |
Correct |
0 ms |
13444 KB |
Output is correct |
3 |
Correct |
4 ms |
13316 KB |
Output is correct |
4 |
Correct |
0 ms |
13316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
13316 KB |
Output is correct |
2 |
Correct |
0 ms |
13316 KB |
Output is correct |
3 |
Correct |
4 ms |
13316 KB |
Output is correct |
4 |
Correct |
0 ms |
13316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
13708 KB |
Output is correct |
2 |
Correct |
24 ms |
13316 KB |
Output is correct |
3 |
Correct |
28 ms |
14368 KB |
Output is correct |
4 |
Correct |
40 ms |
13316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
13448 KB |
Output is correct |
2 |
Correct |
4 ms |
13448 KB |
Output is correct |
3 |
Correct |
24 ms |
14236 KB |
Output is correct |
4 |
Correct |
8 ms |
13448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
13448 KB |
Output is correct |
2 |
Correct |
20 ms |
13448 KB |
Output is correct |
3 |
Correct |
36 ms |
13708 KB |
Output is correct |
4 |
Correct |
8 ms |
13316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
13708 KB |
Output is correct |
2 |
Correct |
48 ms |
13316 KB |
Output is correct |
3 |
Correct |
92 ms |
14368 KB |
Output is correct |
4 |
Correct |
16 ms |
13316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
13708 KB |
Output is correct |
2 |
Correct |
108 ms |
14368 KB |
Output is correct |
3 |
Correct |
88 ms |
14236 KB |
Output is correct |
4 |
Correct |
112 ms |
13840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
160 ms |
14236 KB |
Output is correct |
2 |
Correct |
124 ms |
14504 KB |
Output is correct |
3 |
Correct |
128 ms |
14900 KB |
Output is correct |
4 |
Correct |
124 ms |
13316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
160 ms |
14236 KB |
Output is correct |
2 |
Correct |
52 ms |
13316 KB |
Output is correct |
3 |
Correct |
164 ms |
15164 KB |
Output is correct |
4 |
Correct |
40 ms |
13316 KB |
Output is correct |