#include <cstdio>
#include <queue>
#include <utility>
using namespace std;
int main(){
int m,n,h;scanf("%d %d %d",&m,&n,&h);
int table[n][m][h];
for(int k=0;k<h;k++)
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&table[i][j][k]);
queue< pair< pair<int,int>,pair<int,int> > > q;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
for(int k=0;k<h;k++)
if(table[i][j][k]==1)
q.push(make_pair(make_pair(i,j),make_pair(k,0)));
int ans=0;
while(!q.empty()){
int z=q.front().second.first;
int y=q.front().first.first;
int x=q.front().first.second;
int level=q.front().second.second;
int dz[6]={1,0,0,0,0,-1};
int dy[6]={0,1,-1,0,0,0};
int dx[6]={0,0,0,1,-1,0};
if(level>ans)ans=level;
for(int i=0;i<6;i++){
int zz=z+dz[i];
int yy=y+dy[i];
int xx=x+dx[i];
if(zz<h&&zz>=0&&yy<n&&yy>=0&&xx<m&&xx>=0)
if(table[yy][xx][zz]==0){
table[yy][xx][zz]=1;
q.push(make_pair(make_pair(yy,xx),make_pair(zz,level+1)));
//printf("%d %d\n",yy,xx);
}
}
q.pop();
}
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
for(int k=0;k<h;k++)
if(table[i][j][k]==0)ans=-1;
printf("%d",ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
912 KB |
Output is correct |
2 |
Correct |
3 ms |
944 KB |
Output is correct |
3 |
Correct |
0 ms |
912 KB |
Output is correct |
4 |
Correct |
1 ms |
912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
912 KB |
Output is correct |
2 |
Correct |
3 ms |
1052 KB |
Output is correct |
3 |
Correct |
2 ms |
912 KB |
Output is correct |
4 |
Correct |
0 ms |
912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
912 KB |
Output is correct |
2 |
Correct |
0 ms |
912 KB |
Output is correct |
3 |
Correct |
2 ms |
912 KB |
Output is correct |
4 |
Correct |
0 ms |
912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1628 KB |
Output is correct |
2 |
Correct |
27 ms |
1496 KB |
Output is correct |
3 |
Correct |
34 ms |
2592 KB |
Output is correct |
4 |
Correct |
53 ms |
2148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1196 KB |
Output is correct |
2 |
Correct |
4 ms |
1072 KB |
Output is correct |
3 |
Correct |
31 ms |
2360 KB |
Output is correct |
4 |
Correct |
9 ms |
1172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
1776 KB |
Output is correct |
2 |
Correct |
32 ms |
1552 KB |
Output is correct |
3 |
Correct |
48 ms |
2116 KB |
Output is correct |
4 |
Correct |
16 ms |
1124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
3360 KB |
Output is correct |
2 |
Correct |
53 ms |
2148 KB |
Output is correct |
3 |
Correct |
136 ms |
4204 KB |
Output is correct |
4 |
Correct |
18 ms |
1256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
3436 KB |
Output is correct |
2 |
Correct |
139 ms |
4324 KB |
Output is correct |
3 |
Correct |
100 ms |
3808 KB |
Output is correct |
4 |
Correct |
152 ms |
4116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
209 ms |
5432 KB |
Output is correct |
2 |
Correct |
144 ms |
5072 KB |
Output is correct |
3 |
Correct |
149 ms |
5572 KB |
Output is correct |
4 |
Correct |
137 ms |
4744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
188 ms |
5664 KB |
Output is correct |
2 |
Correct |
62 ms |
2708 KB |
Output is correct |
3 |
Correct |
189 ms |
6620 KB |
Output is correct |
4 |
Correct |
51 ms |
2404 KB |
Output is correct |