This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |