#include <cstdio>
#include <queue>
#include <utility>
using namespace std;
int main(){
int m,n;scanf("%d %d",&m,&n);
int table[n][m];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&table[i][j]);
queue<pair<pair<int,int>,int> > q;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(table[i][j]==1)
q.push(make_pair(make_pair(i,j),0));
int ans=0;
while(!q.empty()){
int y=q.front().first.first;
int x=q.front().first.second;
int level=q.front().second;
int dy[4]={1,0,0,-1};
int dx[4]={0,-1,1,0};
if(level>ans)ans=level;
for(int i=0;i<4;i++){
int yy=y+dy[i];
int xx=x+dx[i];
if(yy<n&&yy>=0&&xx<m&&xx>=0)
if(table[yy][xx]==0){
table[yy][xx]=1;
q.push(make_pair(make_pair(yy,xx),level+1));
//printf("%d %d\n",yy,xx);
}
}
q.pop();
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(table[i][j]==0)ans=-1;
}
}
printf("%d",ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1236 KB |
Output is correct |
2 |
Correct |
0 ms |
1236 KB |
Output is correct |
3 |
Correct |
0 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1236 KB |
Output is correct |
2 |
Correct |
0 ms |
1236 KB |
Output is correct |
3 |
Correct |
0 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1236 KB |
Output is correct |
2 |
Correct |
0 ms |
1236 KB |
Output is correct |
3 |
Correct |
0 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1252 KB |
Output is correct |
2 |
Correct |
4 ms |
1256 KB |
Output is correct |
3 |
Correct |
0 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1236 KB |
Output is correct |
2 |
Correct |
0 ms |
1236 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1236 KB |
Output is correct |
2 |
Correct |
4 ms |
1260 KB |
Output is correct |
3 |
Correct |
0 ms |
1236 KB |
Output is correct |
4 |
Correct |
4 ms |
1268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
2372 KB |
Output is correct |
2 |
Correct |
24 ms |
1928 KB |
Output is correct |
3 |
Correct |
8 ms |
1520 KB |
Output is correct |
4 |
Correct |
8 ms |
1504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
2780 KB |
Output is correct |
2 |
Correct |
48 ms |
2684 KB |
Output is correct |
3 |
Correct |
8 ms |
1332 KB |
Output is correct |
4 |
Correct |
8 ms |
1412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
2176 KB |
Output is correct |
2 |
Correct |
96 ms |
4476 KB |
Output is correct |
3 |
Correct |
12 ms |
1504 KB |
Output is correct |
4 |
Correct |
64 ms |
3236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
5148 KB |
Output is correct |
2 |
Correct |
132 ms |
5284 KB |
Output is correct |
3 |
Correct |
108 ms |
5020 KB |
Output is correct |
4 |
Correct |
96 ms |
4240 KB |
Output is correct |