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 <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 (stderr)
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]
# | 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... |