Submission #7715

#TimeUsernameProblemLanguageResultExecution timeMemory
7715jinho0605토마토 (KOI13_tomato)C++98
16 / 16
136 ms8900 KiB
#include<stdio.h> #define MAX 500000 int arr[1000][1000],front=0,rear=0,cnt=2,m=0,n=0,day=0; typedef struct data{ int i; int j; }; data queue[MAX]; int main() { int to_i[4]={-1,0,1,0}; int to_j[4]={0,-1,0,1}; int M,N; scanf("%d %d",&M,&N); for(int i=0;i<N;i++) { for(int j=0;j<M;j++) { scanf("%d",&arr[i][j]); if(arr[i][j]==1) { rear=(rear+1)%MAX; queue[rear].i=i; queue[rear].j=j; m++; } } } while(rear!=front) { front=(front+1)%MAX; for(int k=0;k<4;k++) { if(queue[front].i+to_i[k]<N && queue[front].i+to_i[k]>=0 && queue[front].j+to_j[k]<M && queue[front].j+to_j[k]>=0) { if(!arr[queue[front].i+to_i[k]][queue[front].j+to_j[k]]) { arr[queue[front].i+to_i[k]][queue[front].j+to_j[k]]=cnt; rear=(rear+1)%MAX; queue[rear].i=queue[front].i+to_i[k]; queue[rear].j=queue[front].j+to_j[k]; n++; } } } m--; queue[front].i=queue[front].j=0; if(m==0) { cnt++; m=n; n=0; day++; } } for(int i=0;i<N;i++) { for(int j=0;j<M;j++) { if(arr[i][j]==0) { printf("-1"); return 0; } } } printf("%d",day-1); 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...