답안 #5227

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5227 2014-02-19T11:24:14 Z gs13105 토마토 (3차원) (KOI13_tomato3D) C++
20 / 20
156 ms 6592 KB
#include <stdio.h>
#include <queue>

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

typedef std::pair<int,int> P1;
typedef std::pair<P1,int> P2;
typedef std::queue<P2> Q;

Q q;
int arr[100][100][100];
int dx[6]={1,0,0,-1,0,0};
int dy[6]={0,1,0,0,-1,0};
int dz[6]={0,0,1,0,0,-1};

int main()
{
	int s=0,c=0,p=0,d=0,m,n,h,nx,ny,nz,i,j,k;
	scanf("%d%d%d",&m,&n,&h);
	for(i=0;i<h;i++)
		for(j=0;j<n;j++)
			for(k=0;k<m;k++)
				scanf("%d",&arr[i][j][k]);
	for(i=0;i<h;i++)
	{
		for(j=0;j<n;j++)
		{
			for(k=0;k<m;k++)
			{
				if(arr[i][j][k]==1)
				{
					q.push(m(m(i,j),k));
					p++;
				}
				if(arr[i][j][k]==0)
					s++;
			}
		}
	}
	while(!q.empty())
	{
		for(i=0;i<6;i++)
		{
			nx=q.front().first.first+dx[i];
			ny=q.front().first.second+dy[i];
			nz=q.front().second+dz[i];
			if(0<=nx&&nx<h&&0<=ny&&ny<n&&0<=nz&&nz<m&&arr[nx][ny][nz]==0)
			{
				arr[nx][ny][nz]=1;
				q.push(m(m(nx,ny),nz));
				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;
}
# 결과 실행 시간 메모리 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 0 ms 5144 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 5144 KB Output is correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 5404 KB Output is correct
2 Correct 20 ms 5144 KB Output is correct
3 Correct 24 ms 5936 KB Output is correct
4 Correct 36 ms 5144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5276 KB Output is correct
2 Correct 4 ms 5272 KB Output is correct
3 Correct 24 ms 5804 KB Output is correct
4 Correct 4 ms 5272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 5144 KB Output is correct
2 Correct 20 ms 5276 KB Output is correct
3 Correct 32 ms 5404 KB Output is correct
4 Correct 12 ms 5144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 5408 KB Output is correct
2 Correct 40 ms 5144 KB Output is correct
3 Correct 92 ms 5932 KB Output is correct
4 Correct 12 ms 5144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 5408 KB Output is correct
2 Correct 80 ms 5932 KB Output is correct
3 Correct 80 ms 5804 KB Output is correct
4 Correct 104 ms 5536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 5804 KB Output is correct
2 Correct 124 ms 6064 KB Output is correct
3 Correct 128 ms 6204 KB Output is correct
4 Correct 120 ms 5144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 5804 KB Output is correct
2 Correct 56 ms 5144 KB Output is correct
3 Correct 156 ms 6592 KB Output is correct
4 Correct 40 ms 5144 KB Output is correct