Submission #5226

# Submission time Handle Problem Language Result Execution time Memory
5226 2014-02-19T11:15:54 Z gs13105 토마토 (KOI13_tomato) C++
16 / 16
124 ms 5276 KB
#include <stdio.h>
#include <queue>

#define m(a,b) std::make_pair(a,b)

typedef std::pair<int,int> P;
typedef std::queue<P> Q;

Q q;
int arr[1000][1000];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int s=0,c=0,p=0,d=0,m,n,nx,ny,i,j;
	scanf("%d%d",&m,&n);
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			scanf("%d",&arr[i][j]);
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(arr[i][j]==1)
			{
				q.push(m(i,j));
				p++;
			}
			if(arr[i][j]==0)
				s++;
		}
	}
	while(!q.empty())
	{
		for(i=0;i<4;i++)
		{
			nx=q.front().first+dx[i];
			ny=q.front().second+dy[i];
			if(0<=nx&&nx<n&&0<=ny&&ny<m&&arr[nx][ny]==0)
			{
				arr[nx][ny]=1;
				q.push(m(nx,ny));
				c++;
				s--;
			}
		}
		q.pop();
		p--;
		if(p==0)
		{
			if(c!=0)
				d++;
			p=c;
			c=0;
		}
	}
	if(s!=0)
		printf("-1");
	else
		printf("%d",d);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5144 KB Output is correct
2 Correct 0 ms 5144 KB Output is correct
3 Correct 0 ms 5144 KB Output is correct
4 Correct 0 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5144 KB Output is correct
2 Correct 0 ms 5144 KB Output is correct
3 Correct 0 ms 5144 KB Output is correct
4 Correct 0 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5144 KB Output is correct
2 Correct 0 ms 5144 KB Output is correct
3 Correct 0 ms 5144 KB Output is correct
4 Correct 0 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5144 KB Output is correct
2 Correct 4 ms 5144 KB Output is correct
3 Correct 0 ms 5144 KB Output is correct
4 Correct 0 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5144 KB Output is correct
2 Correct 0 ms 5144 KB Output is correct
3 Correct 0 ms 5144 KB Output is correct
4 Correct 0 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5144 KB Output is correct
2 Correct 4 ms 5144 KB Output is correct
3 Correct 0 ms 5144 KB Output is correct
4 Correct 4 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 5144 KB Output is correct
2 Correct 24 ms 5144 KB Output is correct
3 Correct 8 ms 5144 KB Output is correct
4 Correct 8 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 5144 KB Output is correct
2 Correct 40 ms 5144 KB Output is correct
3 Correct 4 ms 5144 KB Output is correct
4 Correct 8 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 5144 KB Output is correct
2 Correct 92 ms 5144 KB Output is correct
3 Correct 8 ms 5144 KB Output is correct
4 Correct 56 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 5144 KB Output is correct
2 Correct 124 ms 5276 KB Output is correct
3 Correct 116 ms 5144 KB Output is correct
4 Correct 92 ms 5144 KB Output is correct