Submission #48945

#TimeUsernameProblemLanguageResultExecution timeMemory
48945leehosu01토마토 (KOI13_tomato)C++17
16 / 16
100 ms13288 KiB
#include<bits/stdc++.h> using namespace std; #define able(Y,X) if(0<=X&&X<N&&0<=Y&&Y<M&&D[Y].test(X)==0)Qs.push({Y,X}),D[Y].set(X); bitset<1000>D[1001]; int N,M,to; struct A{int y,x; void mov(queue<A>&Qs) { able(y,x-1); able(y,x+1); able(y-1,x); able(y+1,x); }}; queue<A>Q; int main() { ios::sync_with_stdio(0); cin.tie(0); cin>>N>>M; int a; D[0].reset(); for(int i=0;i<M;D[++i].reset()) for(int j=0;j<N;j++) { cin>>a; if(a==1)D[i].set(j),Q.push({i,j}),++to; if(a==-1)D[i].set(j),++to; } if(to==0)printf("-1"); else if(to==N*M)printf("0"); else { int pl=0; while(to<N*M&&Q.size()) { pl++; for(int i=Q.size();i;--i) { Q.front().mov(Q); Q.pop(); } to+=Q.size(); } printf("%d",to==N*M?pl:-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...