Submission #16232

# Submission time Handle Problem Language Result Execution time Memory
16232 2015-08-18T11:06:10 Z eaststar 토마토 (3차원) (KOI13_tomato3D) C++14
20 / 20
153 ms 21908 KB
#include <stdio.h>
struct data{
	int x,y,z,lev;
}q[1000010];
int a[110][110][110],f,r,cnt;
int dx[]={-1,0,0,0,0,1},dy[]={0,-1,0,1,0,0},dz[]={0,0,1,0,-1,0};
int main(){
	int i,j,k,m,n,h,nx,ny,nz;
	scanf("%d%d%d",&m,&n,&h);
	for(i=h;i>0;--i){
		for(j=1;j<=n;++j){
			for(k=1;k<=m;++k){
				scanf("%d",&a[i][j][k]);
				if(a[i][j][k]==1)q[++r].x=i,q[r].y=j,q[r].z=k;
				if(!a[i][j][k])++cnt;
			}
		}
	}
	while(f<r){
		if(!cnt)break;
		++f;
		for(i=0;i<6;++i){
			nx=q[f].x+dx[i];
			ny=q[f].y+dy[i];
			nz=q[f].z+dz[i];
			if(nx<1||nx>h||ny<1||ny>n||nz<1||nz>m||a[nx][ny][nz])continue;
			q[++r].x=nx,q[r].y=ny,q[r].z=nz,q[r].lev=q[f].lev+1;
			a[nx][ny][nz]=1;
			--cnt;
		}
	}
	if(cnt)printf("-1");
	else printf("%d",q[r].lev);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21908 KB Output is correct
2 Correct 3 ms 21908 KB Output is correct
3 Correct 0 ms 21908 KB Output is correct
4 Correct 0 ms 21908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 21908 KB Output is correct
2 Correct 0 ms 21908 KB Output is correct
3 Correct 0 ms 21908 KB Output is correct
4 Correct 0 ms 21908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21908 KB Output is correct
2 Correct 0 ms 21908 KB Output is correct
3 Correct 3 ms 21908 KB Output is correct
4 Correct 0 ms 21908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 21908 KB Output is correct
2 Correct 18 ms 21908 KB Output is correct
3 Correct 28 ms 21908 KB Output is correct
4 Correct 54 ms 21908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 21908 KB Output is correct
2 Correct 0 ms 21908 KB Output is correct
3 Correct 26 ms 21908 KB Output is correct
4 Correct 10 ms 21908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 21908 KB Output is correct
2 Correct 27 ms 21908 KB Output is correct
3 Correct 33 ms 21908 KB Output is correct
4 Correct 13 ms 21908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 21908 KB Output is correct
2 Correct 45 ms 21908 KB Output is correct
3 Correct 72 ms 21908 KB Output is correct
4 Correct 19 ms 21908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 21908 KB Output is correct
2 Correct 91 ms 21908 KB Output is correct
3 Correct 75 ms 21908 KB Output is correct
4 Correct 111 ms 21908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 153 ms 21908 KB Output is correct
2 Correct 115 ms 21908 KB Output is correct
3 Correct 91 ms 21908 KB Output is correct
4 Correct 125 ms 21908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 21908 KB Output is correct
2 Correct 46 ms 21908 KB Output is correct
3 Correct 148 ms 21908 KB Output is correct
4 Correct 44 ms 21908 KB Output is correct