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 <deque>
using namespace std;
int a[1010][1010];
int x[5]={0,1,0,-1,0};
deque<int> v1,v2;
int main()
{
int m,n,i,j,t=-1;
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)
{
v1.push_back(i);
v2.push_back(j);
}
else
a[i][j]--;
}
while(v1.size()!=0)
{
int s=v1.size();
for(i=0;i<s;i++)
{
for(int k=0;k<=3;k++)
{
if(a[v1.front()+x[k]][v2.front()+x[k+1]]==-1)
{
a[v1.front()+x[k]][v2.front()+x[k+1]]++;
v1.push_back(v1.front()+x[k]);
v2.push_back(v2.front()+x[k+1]);
}
}
v1.pop_front();
v2.pop_front();
}
t++;
}
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if(a[i][j]==-1)
break;
if(i==n+1 && j==m+1)
printf("%d",t);
else
printf("-1");
}
# | 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... |