Submission #14191

#TimeUsernameProblemLanguageResultExecution timeMemory
14191paulsohn토마토 (KOI13_tomato)C++98
16 / 16
144 ms7012 KiB
#include<cstdio> #include<queue> using namespace std; struct info{ int x,y,d; info(){} info(int x,int y,int d){ this->x=x; this->y=y; this->d=d; } }; queue<info> Q; int N,M,box[1010][1010],D=0,R; int main(){ int i,j; scanf("%d%d",&M,&N); R=M*N; for(i=0;i<N;++i){ for(j=0;j<M;++j){ scanf("%d",&box[i][j]); if(box[i][j]==-1) --R; else if(box[i][j]==1){ Q.push(info(i-1,j,1)); Q.push(info(i+1,j,1)); Q.push(info(i,j-1,1)); Q.push(info(i,j+1,1)); --R; } } } while(!Q.empty()){ info I=Q.front(); Q.pop(); if(I.x>=0 && I.x<N && I.y>=0 && I.y<M && box[I.x][I.y]==0){ D=I.d; box[I.x][I.y]=1; --R; Q.push(info(I.x-1,I.y,I.d+1)); Q.push(info(I.x+1,I.y,I.d+1)); Q.push(info(I.x,I.y-1,I.d+1)); Q.push(info(I.x,I.y+1,I.d+1)); } } if(R) 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...