Submission #1180

#TimeUsernameProblemLanguageResultExecution timeMemory
1180gs13068토마토 (3차원) (KOI13_tomato3D)C++98
20 / 20
180 ms20416 KiB
#include<cstdio> int d[100][100][100]; int a[100][100][100]; int qx[1000000]; int qy[1000000]; int qz[1000000]; int qn; int px[6]={1,-1,0,0,0,0}; int py[6]={0,0,1,-1,0,0}; int pz[6]={0,0,0,0,1,-1}; int main() { int x,y,z,dest=0; int i,j,k,n,m,l; scanf("%d%d%d",&l,&m,&n); for(i=0;i<n;i++)for(j=0;j<m;j++)for(k=0;k<l;k++)scanf("%d",&a[i][j][k]); for(i=0;i<n;i++)for(j=0;j<m;j++)for(k=0;k<l;k++) { if(a[i][j][k]==1) { d[i][j][k]=1; qx[qn]=i; qy[qn]=j; qz[qn]=k; qn++; } if(a[i][j][k]>=0) dest++; } for(i=0;i<qn;i++) { x=qx[i]; y=qy[i]; z=qz[i]; for(j=0;j<6;j++) { x+=px[j]; y+=py[j]; z+=pz[j]; if(x>=0&&x<n&&y>=0&&y<m&&z>=0&&z<l&&a[x][y][z]==0&&!d[x][y][z]) { d[x][y][z]=d[qx[i]][qy[i]][qz[i]]+1; qx[qn]=x; qy[qn]=y; qz[qn]=z; qn++; } x-=px[j]; y-=py[j]; z-=pz[j]; } } if(qn<dest)puts("-1"); else printf("%d",d[qx[qn-1]][qy[qn-1]][qz[qn-1]]-1); }
#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...