Submission #5227

#TimeUsernameProblemLanguageResultExecution timeMemory
5227gs13105토마토 (3차원) (KOI13_tomato3D)C++98
20 / 20
156 ms6592 KiB
#include <stdio.h> #include <queue> #define m(a,b) std::make_pair(a,b) typedef std::pair<int,int> P1; typedef std::pair<P1,int> P2; typedef std::queue<P2> Q; Q q; int arr[100][100][100]; int dx[6]={1,0,0,-1,0,0}; int dy[6]={0,1,0,0,-1,0}; int dz[6]={0,0,1,0,0,-1}; int main() { int s=0,c=0,p=0,d=0,m,n,h,nx,ny,nz,i,j,k; scanf("%d%d%d",&m,&n,&h); for(i=0;i<h;i++) for(j=0;j<n;j++) for(k=0;k<m;k++) scanf("%d",&arr[i][j][k]); for(i=0;i<h;i++) { for(j=0;j<n;j++) { for(k=0;k<m;k++) { if(arr[i][j][k]==1) { q.push(m(m(i,j),k)); p++; } if(arr[i][j][k]==0) s++; } } } while(!q.empty()) { for(i=0;i<6;i++) { nx=q.front().first.first+dx[i]; ny=q.front().first.second+dy[i]; nz=q.front().second+dz[i]; if(0<=nx&&nx<h&&0<=ny&&ny<n&&0<=nz&&nz<m&&arr[nx][ny][nz]==0) { arr[nx][ny][nz]=1; q.push(m(m(nx,ny),nz)); c++; s--; } } q.pop(); p--; if(p==0) { if(c!=0) d++; p=c; c=0; } } if(s!=0) printf("-1"); else printf("%d",d); 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...