# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
14238 | moonrabbit2 | 토마토 (3차원) (KOI13_tomato3D) | C11 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define MAX 100
int queue[3][MAX*MAX*MAX],check[MAX][MAX][MAX],a[MAX][MAX][MAX],top,place,m,n,h,count=1,nmax;
void queueinsert(int x,int y,int z,int c)
{
queue[0][top]=x;
queue[1][top]=y;
queue[2][top++]=z;
check[x][y][z]=c;
}
void put(int x,int y,int z)
{
int c=check[x][y][z];
if(y-1<0||check[x][y-1][z]!=0||a[x][y-1][z]==-1);
else queueinsert(x,y-1,z,c+1);
if(y+1>=n||check[x][y+1][z]!=0||a[x][y+1][z]==-1);
else queueinsert(x,y+1,z,c+1);
if(z-1<0||check[x][y][z-1]!=0||a[x][y][z-1]==-1);
else queueinsert(x,y,z-1,c+1);
if(z+1>=m||check[x][y][z+1]!=0||a[x][y][z+1]==-1);
else queueinsert(x,y,z+1,c+1);
if(x-1<0||check[x-1][y][z]!=0||a[x-1][y][z]==-1);
else queueinsert(x-1,y,z,c+1);
if(x+1>=h||check[x+1][y][z]!=0||a[x+1][y][z]==-1);
else queueinsert(x+1,y,z,c+1);
}
int main()
{
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)queueinsert(i,j,k,1);
}
}
}
while(m*n*h!=count){
if(check[queue[0][place]][queue[1][place]][queue[2][place]]!=0&&a[queue[0][place]][queue[1][place]][queue[2][place]]!=-1){
put(queue[0][place],queue[1][place],queue[2][place]);
place++;
}
count++;
}
for(int i=0;i<h;i++){
for(int j=0;j<n;j++){
for(int k=0;k<m;k++){
if(check[i][j][k]==0&&a[i][j][k]==0){
printf("-1");
return 0;
}
if(check[i][j][k]>nmax)nmax=check[i][j][k];
}
}
}
printf("%d",nmax-1);
return 0;
}