Submission #4954

#TimeUsernameProblemLanguageResultExecution timeMemory
4954ansol4328토마토 (3차원) (KOI13_tomato3D)C++98
20 / 20
188 ms44772 KiB
#include<stdio.h> int n, m, h; int map[102][102][102], time[102][102][102], check[102][102][102]; int out; int q[2000004][4], r=0, f=0; int main() { int i, j, k, a=0, maxt=0; int y, x, z, st; int dz[6]={1,-1,0,0,0,0}; int dy[6]={0,0,-1,0,1,0}; int dx[6]={0,0,0,1,0,-1}; 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",&map[i][j][k]); if(map[i][j][k]==0) a++; if(map[i][j][k]==1) { r++; q[r][1]=i, q[r][2]=j, q[r][3]=k; } } } } st=r; do { f++; z=q[f][1], y=q[f][2], x=q[f][3]; check[z][y][x]=1; for(i=0 ; i<6 ; i++) { if(z+dz[i]>=1 && z+dz[i]<=h && y+dy[i]>=1 && y+dy[i]<=n && x+dx[i]>=1 && x+dx[i]<=m && check[z+dz[i]][y+dy[i]][x+dx[i]]==0 && map[z+dz[i]][y+dy[i]][x+dx[i]]==0) { check[z+dz[i]][y+dy[i]][x+dx[i]]=1; r++; q[r][1]=z+dz[i], q[r][2]=y+dy[i], q[r][3]=x+dx[i]; time[z+dz[i]][y+dy[i]][x+dx[i]]=time[z][y][x]+1; if(maxt<time[z+dz[i]][y+dy[i]][x+dx[i]]) maxt=time[z+dz[i]][y+dy[i]][x+dx[i]]; } } }while(f<r); if(r-st==a) out=maxt; else if(a==0) out=0; else if(r-st!=a) out=-1; printf("%d",out); 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...