Submission #544639

#TimeUsernameProblemLanguageResultExecution timeMemory
544639pokmui9909토마토 (3차원) (KOI13_tomato3D)C++17
20 / 20
133 ms13036 KiB
#include <bits/stdc++.h> using namespace std; int n, m, h; int visited[105][105][105]; int ar[105][105][105]; int xdir[6] = {1, -1, 0, 0, 0, 0}; int ydir[6] = {0, 0, 1, -1, 0, 0}; int zdir[6] = {0, 0, 0, 0, 1, -1}; struct point { int x, y, z, lvl; }; void push(queue<point> &q, int a, int b, int c, int d) { if(a<0 || a>=n || b<0 || b>=m || c<0 || c>=h) return; if(visited[a][b][c]) return; if(ar[a][b][c] == -1) return; visited[a][b][c] = 1; q.push({a, b, c, d}); } int bfs() { queue<point> q; int ans = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { for(int k = 0; k < h; k++) { if(ar[i][j][k] == 1) push(q, i, j, k, 0); } } } while(!q.empty()) { ans = max(ans, q.front().lvl); int x=q.front().x, y=q.front().y, z=q.front().z; int lvl = q.front().lvl; q.pop(); for(int i = 0; i < 6; i++) push(q, x+xdir[i], y+ydir[i], z+zdir[i], lvl+1); } return ans; } int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); cin >> m >> n >> h; for(int i = 0; i < h; i++) { for(int j = 0; j < n; j++) { for(int k = 0; k < m; k++) { cin >> ar[j][k][i]; } } } int ans = bfs(); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { for(int k = 0; k < h; k++) { if(ar[i][j][k] == 0 && visited[i][j][k] == 0) { cout << -1; return 0; } } } }cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...