#include <stdio.h>
int Queuex[500001], Queuey[500001], Queuez[500001], Time[500001], check=0, checking=0;
int front=1, rear=1, tomato[101][201][101], visit[101][201][101];
int Dirx[8]={0, -1, 1, 0, 0, 0, 0}, Diry[8]={0, 0, 0, -1, 1, 0, 0}, Dirz[8]={0, 0, 0, 0, 0, -1, 1};
void push(int a, int b, int c, int t)
{
Queuex[rear] = a;
Queuey[rear] = b;
Queuez[rear] = c;
Time[rear] = t;
rear++;
}
int Qx()
{
return Queuex[front];
}
int Qy()
{
return Queuey[front];
}
int Qz()
{
return Queuez[front++];
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n, k, l, tle=0, res=0, tmp=0;
int i, j, a;
int x1=0, x2=0, x3=0;
scanf("%d %d %d", &n, &k, &l);
tle=n*k*l;
tmp = n;
n = k;
k = tmp;
for (i=1; i<=l; i++)
{
for (j=1; j<=n; j++)
{
for (a=1; a<=k; a++)
{
scanf("%d", &tomato[i][j][a]);
if (tomato[i][j][a] != 0)
{
check++;
tle--;
}
if (tomato[i][j][a] == 1)
{
push(i, j, a, 0);
visit[i][j][a] = 1;
}
}
}
}
while (front != rear)
{
x1=Qx();
x2=Qy();
x3=Qz();
res++;
for (i=1; i<=6; i++)
{
if (tomato[x1+Dirx[i]][x2+Diry[i]][x3+Dirz[i]] == 0 && visit[x1+Dirx[i]][x2+Diry[i]][x3+Dirz[i]] == 0
&& x1+Dirx[i] > 0 && x1+Dirx[i] <= l && x2+Diry[i] > 0 && x2+Diry[i] <= n && x3+Dirz[i] > 0 && x3+Dirz[i] <= k)
{
tle--;
tomato[x1+Dirx[i]][x2+Diry[i]][x3+Dirz[i]] = 1;
push(x1+Dirx[i], x2+Diry[i], x3+Dirz[i], Time[res]+1);
visit[x1+Dirx[i]][x2+Diry[i]][x3+Dirz[i]] = 1;
}
}
if (tle == 0) break;
}
for (i=1; i<=l; i++)
{
for (j=1; j<=n; j++)
{
for (a=1; a<=k; a++)
{
if (tomato[i][j][a] == -1 || tomato[i][j][a] == 1)
{
checking++;
}
}
}
}
if (n*k*l == checking) printf("%d", Time[rear-1]);
else printf("-1");
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
24616 KB |
Output is correct |
2 |
Correct |
3 ms |
24616 KB |
Output is correct |
3 |
Correct |
0 ms |
24616 KB |
Output is correct |
4 |
Correct |
0 ms |
24616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
24616 KB |
Output is correct |
2 |
Correct |
4 ms |
24616 KB |
Output is correct |
3 |
Correct |
2 ms |
24616 KB |
Output is correct |
4 |
Correct |
0 ms |
24616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
24616 KB |
Output is correct |
2 |
Correct |
0 ms |
24616 KB |
Output is correct |
3 |
Correct |
1 ms |
24616 KB |
Output is correct |
4 |
Correct |
0 ms |
24616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
24616 KB |
Output is correct |
2 |
Correct |
20 ms |
24616 KB |
Output is correct |
3 |
Correct |
27 ms |
24616 KB |
Output is correct |
4 |
Correct |
40 ms |
24616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
24616 KB |
Output is correct |
2 |
Correct |
4 ms |
24616 KB |
Output is correct |
3 |
Correct |
26 ms |
24616 KB |
Output is correct |
4 |
Correct |
9 ms |
24616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
24616 KB |
Output is correct |
2 |
Correct |
19 ms |
24616 KB |
Output is correct |
3 |
Correct |
40 ms |
24616 KB |
Output is correct |
4 |
Correct |
11 ms |
24616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
96 ms |
24612 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
92 ms |
24612 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
139 ms |
24612 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
142 ms |
24612 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |