This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define able(X,Y) if(0<=X&&X<N&&0<=Y&&Y<M&&D[Y].test(X)==0)Q.push({Y,X}),D[Y].set(X),++to;
bitset<1000>D[1000];
int N,M,to;
struct A{int y,x;
void mov(queue<A>&Q)
{
able(x-1,y);
able(x+1,y);
able(x,y-1);
able(x,y+1);
}};
queue<A>Q;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin>>N>>M;
int a;
for(int i=0;i<M;i++)
for(int j=0;j<N;j++)
{
cin>>a;
if(a)D[i].set(j),Q.push({i,j}),++to;
}
if(to==0)printf("-1");
else
{
int pl=0;
while(to<N*M)
{
pl++;
for(int i=Q.size();i;--i)
{
Q.front().mov(Q);
Q.pop();
}
}
printf("%d",pl);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |