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>
#include <queue>
using namespace std;
queue <int> q;
int m, n, a[1001][1001], d[1001][1001], ans;
int dy[4]={0,1,0,-1}, dx[4]={1,0,-1,0};
void input(void)
{
int i, j;
scanf("%d %d",&m,&n);
for(i=1 ; i<=n ; i++)
for(j=1 ; j<=m ; j++)
{
scanf("%d",&a[i][j]);
if(a[i][j]==1)
{
q.push(i);
q.push(j);
}
}
}
void process(void)
{
int i, j, y, x, ty, tx;
while(!q.empty())
{
y=q.front();
q.pop();
x=q.front();
q.pop();
for(i=0 ; i<=3 ; i++)
{
ty=y+dy[i];
tx=x+dx[i];
if(ty>=1 && ty<=n && tx>=1 && tx<=m)
if(a[ty][tx]==0)
{
a[ty][tx]=1;
d[ty][tx]=d[y][x]+1;
q.push(ty);
q.push(tx);
}
}
}
for(i=1 ; i<=n ; i++)
for(j=1 ; j<=m ; j++)
{
if(a[i][j]==0)
{
ans=-1;
return;
}
if(ans<d[i][j])
ans=d[i][j];
}
}
void output(void)
{
printf("%d",ans);
}
int main(void)
{
input();
process();
output();
return 0;
}
# | 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... |