#include <stdio.h>
#include <queue>
#define M 1009
using namespace std;
struct pp{
int a, b, cost;
pp(){}
pp(int A, int B, int c){
a = A; b = B; cost = c;
}
bool operator<(const pp &q)const{
return cost > q.cost;
}
};
priority_queue<pp> q;
int n, m, s[M][M], ans=-1, chk[M][M];
int x[4] = { 1, -1, 0, 0 }, y[4] = { 0, 0, 1, -1 };
int main(){
int i, j;
scanf("%d %d", &n, &m);
for (i = 1; i <= m; i++){
for (j = 1; j <= n; j++){
scanf("%d", &s[i][j]);
if (s[i][j]==1) q.push(pp(i, j, 0));
}
}
pp e;
while (!q.empty()){
e = q.top(); q.pop();
if (chk[e.a][e.b]) continue;
chk[e.a][e.b] = 1;
ans = max(ans, e.cost);
for (i = 0; i<4; i++)
if (1 <= e.a + x[i] && e.a + x[i] <= m && 1 <= e.b + y[i] && e.b + y[i] <= n && chk[e.a + x[i]][e.b + y[i]] == 0 && s[e.a+x[i]][e.b+y[i]] == 0) q.push(pp(e.a + x[i], e.b + y[i], e.cost + 1));
}
printf("%d", ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
9164 KB |
Output is correct |
2 |
Correct |
0 ms |
9164 KB |
Output is correct |
3 |
Correct |
0 ms |
9164 KB |
Output is correct |
4 |
Correct |
0 ms |
9164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
9164 KB |
Output is correct |
2 |
Correct |
0 ms |
9164 KB |
Output is correct |
3 |
Incorrect |
0 ms |
9164 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
9164 KB |
Output is correct |
2 |
Correct |
0 ms |
9164 KB |
Output is correct |
3 |
Correct |
0 ms |
9164 KB |
Output is correct |
4 |
Correct |
0 ms |
9164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9548 KB |
Output is correct |
2 |
Correct |
12 ms |
9744 KB |
Output is correct |
3 |
Correct |
0 ms |
9164 KB |
Output is correct |
4 |
Correct |
0 ms |
9164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9164 KB |
Output is correct |
2 |
Correct |
0 ms |
9164 KB |
Output is correct |
3 |
Correct |
12 ms |
9164 KB |
Output is correct |
4 |
Correct |
8 ms |
9164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
9164 KB |
Output is correct |
2 |
Correct |
4 ms |
9164 KB |
Output is correct |
3 |
Correct |
0 ms |
9164 KB |
Output is correct |
4 |
Correct |
4 ms |
9164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
9356 KB |
Output is correct |
2 |
Correct |
28 ms |
9164 KB |
Output is correct |
3 |
Correct |
36 ms |
9356 KB |
Output is correct |
4 |
Correct |
32 ms |
9164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
9548 KB |
Output is correct |
2 |
Correct |
136 ms |
9744 KB |
Output is correct |
3 |
Correct |
16 ms |
9356 KB |
Output is correct |
4 |
Correct |
24 ms |
9164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
9356 KB |
Output is correct |
2 |
Correct |
116 ms |
9164 KB |
Output is correct |
3 |
Correct |
32 ms |
9356 KB |
Output is correct |
4 |
Correct |
72 ms |
9164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
392 ms |
9744 KB |
Output is correct |
2 |
Correct |
392 ms |
10320 KB |
Output is correct |
3 |
Correct |
140 ms |
9164 KB |
Output is correct |
4 |
Correct |
96 ms |
9164 KB |
Output is correct |