Submission #16233

# Submission time Handle Problem Language Result Execution time Memory
16233 2015-08-18T11:06:57 Z eaststar 토마토 (KOI13_tomato) C++14
16 / 16
98 ms 161316 KB
#include <stdio.h>
struct data{
	int x,y,z,lev;
}q[10000010];
int a[1010][1010],f,r,cnt;
int dy[]={-1,0,1,0},dz[]={0,1,0,-1};
int main(){
	int j,k,m,n,ny,nz;
	scanf("%d%d",&m,&n);
	for(j=1;j<=n;++j){
		for(k=1;k<=m;++k){
			scanf("%d",&a[j][k]);
			if(a[j][k]==1)q[++r].y=j,q[r].z=k;
			if(!a[j][k])++cnt;
		}
	}
	while(f<r){
		++f;
		for(j=0;j<4;++j){
			ny=q[f].y+dy[j];
			nz=q[f].z+dz[j];
			if(ny<1||ny>n||nz<1||nz>m||a[ny][nz])continue;
			q[++r].y=ny,q[r].z=nz,q[r].lev=q[f].lev+1;
			a[ny][nz]=1;
			--cnt;
		}
		if(!cnt)break;
	}
	if(cnt)printf("-1");
	else printf("%d",q[r].lev);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 161316 KB Output is correct
2 Correct 0 ms 161316 KB Output is correct
3 Correct 0 ms 161316 KB Output is correct
4 Correct 0 ms 161316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 161316 KB Output is correct
2 Correct 0 ms 161316 KB Output is correct
3 Correct 0 ms 161316 KB Output is correct
4 Correct 0 ms 161316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 161316 KB Output is correct
2 Correct 0 ms 161316 KB Output is correct
3 Correct 0 ms 161316 KB Output is correct
4 Correct 0 ms 161316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 161316 KB Output is correct
2 Correct 6 ms 161316 KB Output is correct
3 Correct 0 ms 161316 KB Output is correct
4 Correct 0 ms 161316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 161316 KB Output is correct
2 Correct 0 ms 161316 KB Output is correct
3 Correct 0 ms 161316 KB Output is correct
4 Correct 4 ms 161316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 161316 KB Output is correct
2 Correct 0 ms 161316 KB Output is correct
3 Correct 0 ms 161316 KB Output is correct
4 Correct 6 ms 161316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 161316 KB Output is correct
2 Correct 23 ms 161316 KB Output is correct
3 Correct 8 ms 161316 KB Output is correct
4 Correct 14 ms 161316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 161316 KB Output is correct
2 Correct 53 ms 161316 KB Output is correct
3 Correct 7 ms 161316 KB Output is correct
4 Correct 6 ms 161316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 161316 KB Output is correct
2 Correct 98 ms 161316 KB Output is correct
3 Correct 12 ms 161316 KB Output is correct
4 Correct 68 ms 161316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 161316 KB Output is correct
2 Correct 97 ms 161316 KB Output is correct
3 Correct 88 ms 161316 KB Output is correct
4 Correct 88 ms 161316 KB Output is correct