#include <bits/stdc++.h>
using namespace std;
struct Point {
int x;
int y;
int z;
};
Point make_Point(int z, int y, int x);
int f();
const int flag = 999999999;
queue<Point> que;
int seat[110][110][100];
int width, height, length, cnt;
int main(void)
{
int z, y, x;
scanf("%d%d%d", &width, &height, &length);
for(z=0;z<length;z++) {
for(y=0;y<height;y++) {
for(x=0;x<width;x++) {
scanf("%d", &seat[z][y][x]);
if(seat[z][y][x] == 1) {
que.push(make_Point(z, y, x));
seat[z][y][x] += flag;
}
else if(seat[z][y][x] == 0) {
cnt++;
}
}
}
}
printf("%d\n", f());
return 0;
}
Point make_Point(int z, int y, int x)
{
Point res;
res.z = z;
res.y = y;
res.x = x;
return res;
}
int f()
{
Point p;
int dz[6] = {-1, 1, 0, 0, 0, 0};
int dy[6] = {0, 0, -1, 1, 0, 0};
int dx[6] = {0, 0, 0, 0, -1, 1};
int i;
while(!que.empty()) {
p = que.front();
que.pop();
for(i=0;i<6;i++) {
Point next = make_Point(p.z+dz[i], p.y+dy[i], p.x+dx[i]);
if(next.z >= 0 && next.z < length && next.y >= 0 && next.y < height && next.x >= 0 && next.x < width) {
if(seat[next.z][next.y][next.x] == 0) {
seat[next.z][next.y][next.x] = seat[p.z][p.y][p.x] + 1;
que.push(next);
cnt--;
}
}
}
}
if(cnt <= 0) {
return seat[p.z][p.y][p.x] - flag - 1;
}
return -1;
}
Compilation message
cc.cpp: In function 'int main()':
cc.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &width, &height, &length);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc.cpp:28:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &seat[z][y][x]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
cc.cpp: In function 'int f()':
cc.cpp:81:34: warning: 'p.Point::z' may be used uninitialized in this function [-Wmaybe-uninitialized]
return seat[p.z][p.y][p.x] - flag - 1;
~~~~~~~~~~~~~~~~~~^
cc.cpp:81:34: warning: 'p.Point::y' may be used uninitialized in this function [-Wmaybe-uninitialized]
cc.cpp:81:34: warning: 'p.Point::x' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
760 KB |
Output is correct |
2 |
Correct |
5 ms |
888 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
6 ms |
1528 KB |
Output is correct |
3 |
Correct |
5 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
1528 KB |
Output is correct |
2 |
Correct |
20 ms |
1784 KB |
Output is correct |
3 |
Correct |
27 ms |
2424 KB |
Output is correct |
4 |
Correct |
36 ms |
3060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1016 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
24 ms |
2300 KB |
Output is correct |
4 |
Correct |
9 ms |
1016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
2424 KB |
Output is correct |
2 |
Correct |
23 ms |
2168 KB |
Output is correct |
3 |
Correct |
33 ms |
2808 KB |
Output is correct |
4 |
Correct |
12 ms |
1400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
5168 KB |
Output is correct |
2 |
Correct |
39 ms |
3320 KB |
Output is correct |
3 |
Correct |
82 ms |
5636 KB |
Output is correct |
4 |
Correct |
12 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
4884 KB |
Output is correct |
2 |
Correct |
87 ms |
5908 KB |
Output is correct |
3 |
Correct |
73 ms |
4728 KB |
Output is correct |
4 |
Correct |
98 ms |
6140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
7064 KB |
Output is correct |
2 |
Correct |
105 ms |
6520 KB |
Output is correct |
3 |
Correct |
116 ms |
6904 KB |
Output is correct |
4 |
Correct |
111 ms |
7436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
7268 KB |
Output is correct |
2 |
Correct |
54 ms |
3768 KB |
Output is correct |
3 |
Correct |
149 ms |
8140 KB |
Output is correct |
4 |
Correct |
45 ms |
3192 KB |
Output is correct |