Submission #1118

# Submission time Handle Problem Language Result Execution time Memory
1118 2013-06-26T05:49:52 Z jiws829 토마토 (KOI13_tomato) C++
0 / 16
1000 ms 5000 KB
#include<stdio.h>
int n,m;
int p[1001][1001];
int check()
{
	int i,j;
	int r=0,a=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(p[i][j]==1) r=1;
			if(p[i][j]==0) a=1;
		}
	}
	if(a==1 && r==1) return 0;
	if(a==0 && r==1) return 1;
	if(r==0) return -1;
}
void make()
{
	int i,j;
	
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			if(p[i][j]==1)
			{
				p[i-1][j]=p[i+1][j]=p[i][j-1]=p[i][j+1]=2;
			}
		}
	}
}
int main()
{

	scanf("%d %d",&m,&n);
	
	int i,j,k,r;
	
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			scanf("%d",&p[i][j]);
		}
	}
	
	for(k=0;;k++)
	{
		r=check();
		if(r) break;
		make();
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=m;j++)
			{
				if(p[i][j]==2)
				{
					p[i][j]=1;
				}
			}
		}
		
		if(r==1) break;
	}
	if(r==-1) printf("-1");
	else printf("%d\n",k);	
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 4996 KB Program timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 4996 KB Program timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 4996 KB Program timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 4996 KB Program timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 4996 KB Program timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5000 KB Output is correct
2 Execution timed out 1000 ms 4996 KB Program timed out
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 4996 KB Program timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 4996 KB Program timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 4996 KB Program timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 4996 KB Program timed out
2 Halted 0 ms 0 KB -