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>
struct QUEUE {
int i, j;
} q[1000001];
int f = 0, l = 0;
int x[1000][1000];
int I, J, remain = 0;
void inqueue(int i, int j)
{
q[l].i = i;
q[l].j = j;
l++;
}
int main(void)
{
int i, j, t = 0, s = 0;
scanf("%d %d", &I, &J);
for(j = 0; j < J; j++)
{
for(i = 0; i < I; i++)
{
scanf("%d", &x[j][i]);
if(x[j][i] == 1)
inqueue(i, j);
else if(x[j][i] == 0)
remain++;
}
}
while(t < l)
{
for(t = l; f < t; f++)
{
i = q[f].i;
j = q[f].j;
if(j > 0 && x[j - 1][i] == 0)
{
inqueue(i, j - 1);
x[j - 1][i] = 1;
remain--;
}
if(j < J - 1 && x[j + 1][i] == 0)
{
inqueue(i, j + 1);
x[j + 1][i] = 1;
remain--;
}
if(i > 0 && x[j][i - 1] == 0)
{
inqueue(i - 1, j);
x[j][i - 1] = 1;
remain--;
}
if(i < I - 1 && x[j][i + 1] == 0)
{
inqueue(i + 1, j);
x[j][i + 1] = 1;
remain--;
}
}
s++;
}
if(remain > 0)
printf("-1\n");
else
printf("%d\n", s - 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... |