#include<bits/stdc++.h>
using namespace std;
struct data{
int x,y,z,lev;
};
queue<data> que;
int m,n,h,a[110][110][110],visit[110][110][110],cnt,tot;
int dr[]={1,-1,0,0,0,0},dc[]={0,0,1,-1,0,0},du[]={0,0,0,0,1,-1};
void push(int x,int y,int z,int level){
if(x<1||y<1||z<1||x>n||y>m||z>h||visit[x][y][z]||a[x][y][z]==-1)return;
visit[x][y][z]=1;
cnt++;
que.push({x,y,z,level});
}
int bfs(){
data t;
while(!que.empty()){
t=que.front();
que.pop();
for(int i=0;i<6;i++){
push(t.x+dr[i],t.y+dc[i],t.z+du[i],t.lev+1);
}
}
return t.lev;
}
int main(){
scanf("%d%d%d",&m,&n,&h);
tot=m*n*h;
for(int k=1;k<=h;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%d",&a[i][j][k]);
if(a[i][j][k]==1)push(i,j,k,0);
if(a[i][j][k]==-1)tot--;
}
}
}
int ans=bfs();
if(tot!=cnt)printf("-1");
else printf("%d",ans);
}
Compilation message
cc.cpp: In function 'int main()':
cc.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&m,&n,&h);
~~~~~^~~~~~~~~~~~~~~~~~~
cc.cpp:35:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i][j][k]);
~~~~~^~~~~~~~~~~~~~~~~~
cc.cpp: In function 'int bfs()':
cc.cpp:26:14: warning: 't.data::lev' may be used uninitialized in this function [-Wmaybe-uninitialized]
return t.lev;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1144 KB |
Output is correct |
2 |
Correct |
6 ms |
1400 KB |
Output is correct |
3 |
Correct |
3 ms |
632 KB |
Output is correct |
4 |
Correct |
4 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2808 KB |
Output is correct |
2 |
Correct |
7 ms |
1660 KB |
Output is correct |
3 |
Correct |
5 ms |
888 KB |
Output is correct |
4 |
Correct |
3 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |
3 |
Correct |
5 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
5496 KB |
Output is correct |
2 |
Correct |
26 ms |
6612 KB |
Output is correct |
3 |
Correct |
41 ms |
6904 KB |
Output is correct |
4 |
Correct |
46 ms |
6520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
3064 KB |
Output is correct |
2 |
Correct |
8 ms |
2168 KB |
Output is correct |
3 |
Correct |
35 ms |
6648 KB |
Output is correct |
4 |
Correct |
12 ms |
2060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
4472 KB |
Output is correct |
2 |
Correct |
28 ms |
3736 KB |
Output is correct |
3 |
Correct |
42 ms |
4984 KB |
Output is correct |
4 |
Correct |
15 ms |
2424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
8208 KB |
Output is correct |
2 |
Correct |
44 ms |
6516 KB |
Output is correct |
3 |
Correct |
114 ms |
9600 KB |
Output is correct |
4 |
Correct |
19 ms |
5636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
9164 KB |
Output is correct |
2 |
Correct |
117 ms |
8616 KB |
Output is correct |
3 |
Correct |
98 ms |
8828 KB |
Output is correct |
4 |
Correct |
117 ms |
9592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
12408 KB |
Output is correct |
2 |
Correct |
152 ms |
11192 KB |
Output is correct |
3 |
Correct |
171 ms |
11740 KB |
Output is correct |
4 |
Correct |
121 ms |
12536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
247 ms |
12772 KB |
Output is correct |
2 |
Correct |
68 ms |
8952 KB |
Output is correct |
3 |
Correct |
207 ms |
13688 KB |
Output is correct |
4 |
Correct |
53 ms |
8824 KB |
Output is correct |