#include <stdio.h>
#define N1 100
#define N2 100
#define N3 100
int max(int a, int b) { return a > b ? a : b; }
int main() {
static int aa[N1][N2][N3], dd[N1][N2][N3], qu[N1 * N2 * N3];
int n1, n2, n3, cnt, h, i1, i2, i3, u, d, d_;
scanf("%d%d%d", &n3, &n2, &n1);
for (i1 = 0; i1 < n1; i1++)
for (i2 = 0; i2 < n2; i2++)
for (i3 = 0; i3 < n3; i3++)
scanf("%d", &aa[i1][i2][i3]);
cnt = 0;
for (i1 = 0; i1 < n1; i1++)
for (i2 = 0; i2 < n2; i2++)
for (i3 = 0; i3 < n3; i3++)
if (aa[i1][i2][i3] == 1)
dd[i1][i2][i3] = 0, qu[cnt++] = (i1 * n2 + i2) * n3 + i3;
else
dd[i1][i2][i3] = n1 * n2 * n3;
for (h = 0; h < cnt; h++) {
u = qu[h], i1 = u / n3 / n2, i2 = u / n3 % n2, i3 = u % n3, d = dd[i1][i2][i3] + 1;
if (i1 > 0 && aa[i1 - 1][i2][i3] != -1 && dd[i1 - 1][i2][i3] > d)
dd[i1 - 1][i2][i3] = d, qu[cnt++] = ((i1 - 1) * n2 + i2) * n3 + i3;
if (i1 + 1 < n1 && aa[i1 + 1][i2][i3] != -1 && dd[i1 + 1][i2][i3] > d)
dd[i1 + 1][i2][i3] = d, qu[cnt++] = ((i1 + 1) * n2 + i2) * n3 + i3;
if (i2 > 0 && aa[i1][i2 - 1][i3] != -1 && dd[i1][i2 - 1][i3] > d)
dd[i1][i2 - 1][i3] = d, qu[cnt++] = (i1 * n2 + (i2 - 1)) * n3 + i3;
if (i2 + 1 < n2 && aa[i1][i2 + 1][i3] != -1 && dd[i1][i2 + 1][i3] > d)
dd[i1][i2 + 1][i3] = d, qu[cnt++] = (i1 * n2 + (i2 + 1)) * n3 + i3;
if (i3 > 0 && aa[i1][i2][i3 - 1] != -1 && dd[i1][i2][i3 - 1] > d)
dd[i1][i2][i3 - 1] = d, qu[cnt++] = (i1 * n2 + i2) * n3 + (i3 - 1);
if (i3 + 1 < n3 && aa[i1][i2][i3 + 1] != -1 && dd[i1][i2][i3 + 1] > d)
dd[i1][i2][i3 + 1] = d, qu[cnt++] = (i1 * n2 + i2) * n3 + (i3 + 1);
}
d_ = 0;
for (i1 = 0; i1 < n1; i1++)
for (i2 = 0; i2 < n2; i2++)
for (i3 = 0; i3 < n3; i3++)
if (aa[i1][i2][i3] == 0)
d_ = max(d_, dd[i1][i2][i3]);
printf("%d\n", d_ == n1 * n2 * n3 ? -1 : d_);
return 0;
}
Compilation message
cc.c: In function 'main':
cc.c:13:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d%d%d", &n3, &n2, &n1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc.c:17:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d", &aa[i1][i2][i3]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
2 ms |
1236 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
4 ms |
2388 KB |
Output is correct |
3 |
Correct |
3 ms |
1700 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
976 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2120 KB |
Output is correct |
2 |
Correct |
12 ms |
2740 KB |
Output is correct |
3 |
Correct |
26 ms |
2988 KB |
Output is correct |
4 |
Correct |
42 ms |
5184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1108 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
15 ms |
3000 KB |
Output is correct |
4 |
Correct |
5 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
4160 KB |
Output is correct |
2 |
Correct |
14 ms |
3412 KB |
Output is correct |
3 |
Correct |
21 ms |
4436 KB |
Output is correct |
4 |
Correct |
7 ms |
2204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
8800 KB |
Output is correct |
2 |
Correct |
23 ms |
5736 KB |
Output is correct |
3 |
Correct |
56 ms |
10020 KB |
Output is correct |
4 |
Correct |
7 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
8404 KB |
Output is correct |
2 |
Correct |
64 ms |
10860 KB |
Output is correct |
3 |
Correct |
50 ms |
8376 KB |
Output is correct |
4 |
Correct |
73 ms |
11748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
11476 KB |
Output is correct |
2 |
Correct |
83 ms |
10444 KB |
Output is correct |
3 |
Correct |
74 ms |
10436 KB |
Output is correct |
4 |
Correct |
68 ms |
9036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
11852 KB |
Output is correct |
2 |
Correct |
32 ms |
4888 KB |
Output is correct |
3 |
Correct |
93 ms |
13692 KB |
Output is correct |
4 |
Correct |
27 ms |
5168 KB |
Output is correct |