Submission #7736

#TimeUsernameProblemLanguageResultExecution timeMemory
7736gs14004토마토 (3차원) (KOI13_tomato3D)C++98
20 / 20
164 ms15164 KiB
#include <cstdio> #include <queue> int m,n,h; int a[101][101][101]; int depth[101][101][101]; int v[101][101][101]; std::queue<int> x,y,z,d; void f(int i, int j, int k, int dt){ v[i][j][k]=1; depth[i][j][k]=dt; x.push(i); y.push(j); z.push(k); d.push(dt); } int main(){ // ("input3.txt","r",stdin); scanf("%d %d %d",&m,&n,&h); for (int i=0; i<h; i++) { for (int j=0; j<n; j++) { for (int k=0; k<m; k++) { scanf("%d",&a[i][j][k]); if(a[i][j][k]==1){ f(i,j,k,0); } if(a[i][j][k]==-1){ v[i][j][k]=1; } } } } int cx,cy,cz,cd; while (!x.empty()) { cx = x.front(); cy = y.front(); cz = z.front(); cd = d.front(); if(cx && !v[cx-1][cy][cz]){ f(cx-1,cy,cz,cd+1); } if(cy && !v[cx][cy-1][cz]){ f(cx,cy-1,cz,cd+1); } if(cz && !v[cx][cy][cz-1]){ f(cx,cy,cz-1,cd+1); } if(cx+1<h && !v[cx+1][cy][cz]){ f(cx+1,cy,cz,cd+1); } if(cy+1<n && !v[cx][cy+1][cz]){ f(cx,cy+1,cz,cd+1); } if(cz+1<m && !v[cx][cy][cz+1]){ f(cx,cy,cz+1,cd+1); } x.pop(); y.pop(); z.pop(); d.pop(); } int dtmax = 0; int unvisited = 0; for (int i=0; i<h; i++) { for (int j=0; j<n; j++) { for (int k=0; k<m; k++) { if(dtmax<depth[i][j][k]) dtmax = depth[i][j][k]; if(v[i][j][k]==0) unvisited = 1; } } } if(unvisited) printf("-1"); else printf("%d",dtmax); }
#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...