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