#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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
12804 KB |
Output is correct |
2 |
Correct |
0 ms |
12804 KB |
Output is correct |
3 |
Correct |
0 ms |
12804 KB |
Output is correct |
4 |
Correct |
0 ms |
12804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
12804 KB |
Output is correct |
2 |
Correct |
0 ms |
12804 KB |
Output is correct |
3 |
Correct |
0 ms |
12804 KB |
Output is correct |
4 |
Correct |
0 ms |
12804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
12804 KB |
Output is correct |
2 |
Correct |
0 ms |
12804 KB |
Output is correct |
3 |
Correct |
0 ms |
12804 KB |
Output is correct |
4 |
Correct |
0 ms |
12804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
12804 KB |
Output is correct |
2 |
Correct |
4 ms |
12804 KB |
Output is correct |
3 |
Correct |
0 ms |
12804 KB |
Output is correct |
4 |
Correct |
0 ms |
12804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
12804 KB |
Output is correct |
2 |
Correct |
0 ms |
12804 KB |
Output is correct |
3 |
Correct |
0 ms |
12804 KB |
Output is correct |
4 |
Correct |
0 ms |
12804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
12804 KB |
Output is correct |
2 |
Correct |
4 ms |
12804 KB |
Output is correct |
3 |
Correct |
0 ms |
12804 KB |
Output is correct |
4 |
Correct |
4 ms |
12804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
12804 KB |
Output is correct |
2 |
Correct |
16 ms |
12804 KB |
Output is correct |
3 |
Correct |
12 ms |
12804 KB |
Output is correct |
4 |
Correct |
12 ms |
12804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
12804 KB |
Output is correct |
2 |
Correct |
44 ms |
12804 KB |
Output is correct |
3 |
Correct |
8 ms |
12804 KB |
Output is correct |
4 |
Correct |
8 ms |
12804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
12804 KB |
Output is correct |
2 |
Correct |
104 ms |
12804 KB |
Output is correct |
3 |
Correct |
12 ms |
12804 KB |
Output is correct |
4 |
Correct |
60 ms |
12804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
124 ms |
12804 KB |
Output is correct |
2 |
Correct |
136 ms |
12804 KB |
Output is correct |
3 |
Correct |
108 ms |
12804 KB |
Output is correct |
4 |
Correct |
84 ms |
12804 KB |
Output is correct |