이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <queue>
#define SIZE 110
using namespace std;
typedef struct struct_pos
{
int z;
int y;
int x;
}pos;
queue<pos> q;
int tomato[SIZE][SIZE][SIZE];
int check[SIZE][SIZE][SIZE];
int day, width, length, height;
int dfs();
bool check_fun();
int main()
{
cin >> width >> length >> height;
for(int i = 0; i < height; i++)
{
for(int j = 0; j < length; j++)
{
for(int k = 0; k < width; k++)
{
cin >> tomato[i][j][k];
if(tomato[i][j][k] == 1)
{
q.push({i,j,k});
check[i][j][k] = 1;
}
}
}
}
day = dfs() - 1;
if(check_fun())
{
cout << day << "\n";
return 0;
}
cout << -1 << "\n";
return 0;
}
int dfs()
{
int x, y, z, temp_x, temp_y, temp_z;
int x_pos[] = {0, 1, 0, -1};
int y_pos[] = {1, 0, -1, 0};
int z_pos[] = {1, -1};
while(!q.empty())
{
z = q.front().z;
y = q.front().y;
x = q.front().x;
q.pop();
for(int i = 0; i < 4; i++)
{
temp_y = y + y_pos[i];
temp_x = x + x_pos[i];
if(temp_y < length && temp_y >= 0 && temp_x < width && temp_x >= 0)
{
if((check[z][temp_y][temp_x] == 0 || check[z][temp_y][temp_x] > check[z][y][x] + 1) && tomato[z][temp_y][temp_x] != -1)
{
q.push({z, temp_y, temp_x});
check[z][temp_y][temp_x] = check[z][y][x] + 1;
}
}
}
for(int i = 0; i < 2; i++)
{
temp_z = z + z_pos[i];
if(temp_z < height && temp_z >= 0)
{
if((check[temp_z][y][x] == 0 || check[temp_z][y][x] > check[z][y][x] + 1) && tomato[temp_z][y][x] != -1)
{
q.push({temp_z, y, x});
check[temp_z][y][x] = check[z][y][x] + 1;
}
}
}
}
return check[z][y][x];
}
bool check_fun()
{
for(int i = 0; i < height; i++)
{
for(int j = 0; j < length; j++)
{
for(int k = 0; k < width; k++)
{
if(check[i][j][k] == 0 && tomato[i][j][k] >= 0)
{
return false;
}
}
}
}
return true;
}
컴파일 시 표준 에러 (stderr) 메시지
cc.cpp: In function 'int dfs()':
cc.cpp:85:22: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
85 | return check[z][y][x];
| ^
cc.cpp:85:22: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
cc.cpp:85:22: warning: '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... |