Submission #5310

#TimeUsernameProblemLanguageResultExecution timeMemory
5310baneling100토마토 (3차원) (KOI13_tomato3D)C++98
20 / 20
188 ms10768 KiB
#include <stdio.h> #include <queue> using namespace std; queue <int> q; int m, n, h, a[101][101][101], d[101][101][101], ans; int dz[6]={0,0,0,0,1,-1}, dy[6]={0,1,0,-1,0,0}, dx[6]={1,0,-1,0,0,0}; void input(void) { int i, j, k; scanf("%d %d %d",&m,&n,&h); for(i=1 ; i<=h ; i++) for(j=1 ; j<=n ; j++) for(k=1 ; k<=m ; k++) { scanf("%d",&a[i][j][k]); if(a[i][j][k]==1) { q.push(i); q.push(j); q.push(k); } } } void process(void) { int i, j, k, z, y, x, tz, ty, tx; while(!q.empty()) { z=q.front(); q.pop(); y=q.front(); q.pop(); x=q.front(); q.pop(); for(i=0 ; i<=5 ; i++) { tz=z+dz[i]; ty=y+dy[i]; tx=x+dx[i]; if(tz>=1 && tz<=h && ty>=1 && ty<=n && tx>=1 && tx<=m) if(a[tz][ty][tx]==0) { a[tz][ty][tx]=1; d[tz][ty][tx]=d[z][y][x]+1; q.push(tz); q.push(ty); q.push(tx); } } } for(i=1 ; i<=h ; i++) for(j=1 ; j<=n ; j++) for(k=1 ; k<=m ; k++) { if(a[i][j][k]==0) { ans=-1; return; } if(ans<d[i][j][k]) ans=d[i][j][k]; } } void output(void) { printf("%d",ans); } int main(void) { input(); process(); output(); return 0; }
#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...