#include <stdio.h>
FILE *in=stdin;
FILE *out=stdout;
int m, n, h;
int map[105][105][105], cnt[105][105][105];
int q[1000050][3], f, r, chk;
int x, y, z, dab;
int dx[6] = {-1, 1, 0, 0, 0, 0, };
int dy[6] = {0, 0, -1, 1, 0, 0, };
int dz[6] = {0, 0, 0, 0, -1, 1, };
int main() {
int i, j, l, k;
fscanf(in, "%d%d%d", &m, &n, &h);
for (i=0;i<=h+1;i++) {
for (j=0;j<=n+1;j++) {
for (l=0;l<=m+1;l++) {
map[i][j][l] = -1;
cnt[i][j][l] = 0;
}
}
}
f=r=0;
for (i=1;i<=h;i++) {
for (j=1;j<=n;j++) {
for (l=1;l<=m;l++) {
fscanf(in, "%d", &map[i][j][l]);
if (map[i][j][l] == 1)
{
q[r][0]=i;
q[r][1]=j;
q[r][2]=l;
r++;
}
}
}
}
while (f<r) {
x = q[f][0];
y = q[f][1];
z = q[f][2];
f++;
for (k=0;k<6;k++) {
if (map[x+dx[k]][y+dy[k]][z+dz[k]] == 0)
{
map[x+dx[k]][y+dy[k]][z+dz[k]] = 1;
cnt[x+dx[k]][y+dy[k]][z+dz[k]] =
cnt[x][y][z] + 1;
q[r][0]=x+dx[k];
q[r][1]=y+dy[k];
q[r][2]=z+dz[k];
r++;
}
}
}
dab=0;
chk = -1;
for (i=1;i<=h;i++) {
for (j=1;j<=n;j++) {
for (l=1;l<=m;l++) {
if (dab < cnt[i][j][l])
dab = cnt[i][j][l];
if (map[i][j][l] == 0) chk = 1;
}
}
}if (chk == 1)
fprintf(out, "-1\n");
else fprintf(out, "%d\n", dab);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
21648 KB |
Output is correct |
2 |
Correct |
3 ms |
21648 KB |
Output is correct |
3 |
Correct |
0 ms |
21648 KB |
Output is correct |
4 |
Correct |
0 ms |
21648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
21648 KB |
Output is correct |
2 |
Correct |
2 ms |
21648 KB |
Output is correct |
3 |
Correct |
1 ms |
21648 KB |
Output is correct |
4 |
Correct |
1 ms |
21648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
21648 KB |
Output is correct |
2 |
Correct |
0 ms |
21648 KB |
Output is correct |
3 |
Correct |
2 ms |
21648 KB |
Output is correct |
4 |
Correct |
0 ms |
21648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
21648 KB |
Output is correct |
2 |
Correct |
20 ms |
21648 KB |
Output is correct |
3 |
Correct |
26 ms |
21648 KB |
Output is correct |
4 |
Correct |
31 ms |
21648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
21648 KB |
Output is correct |
2 |
Correct |
3 ms |
21648 KB |
Output is correct |
3 |
Correct |
24 ms |
21648 KB |
Output is correct |
4 |
Correct |
7 ms |
21648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
21648 KB |
Output is correct |
2 |
Correct |
24 ms |
21648 KB |
Output is correct |
3 |
Correct |
35 ms |
21648 KB |
Output is correct |
4 |
Correct |
12 ms |
21648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
21648 KB |
Output is correct |
2 |
Correct |
39 ms |
21648 KB |
Output is correct |
3 |
Correct |
93 ms |
21648 KB |
Output is correct |
4 |
Correct |
13 ms |
21648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
21648 KB |
Output is correct |
2 |
Correct |
97 ms |
21648 KB |
Output is correct |
3 |
Correct |
85 ms |
21648 KB |
Output is correct |
4 |
Correct |
109 ms |
21648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
21648 KB |
Output is correct |
2 |
Correct |
127 ms |
21648 KB |
Output is correct |
3 |
Correct |
129 ms |
21648 KB |
Output is correct |
4 |
Correct |
125 ms |
21648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
160 ms |
21648 KB |
Output is correct |
2 |
Correct |
59 ms |
21648 KB |
Output is correct |
3 |
Correct |
165 ms |
21648 KB |
Output is correct |
4 |
Correct |
46 ms |
21648 KB |
Output is correct |