#include<cstdio>
int n,m,r;
int d;
int t[1010][1010],tmp[1010][1010];
int main(void){
int i,j,k;
bool flag;
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
scanf("%d%d",&n,&m); r=n*m;
for(i=0;i<=n+1;i++) t[0][i]=t[m+1][i]=-1;
for(j=0;j<=m+1;j++) t[j][0]=t[j][n+1]=-1;
for(i=1;i<=m;i++) for(j=1;j<=n;j++){
scanf("%d",&t[i][j]);
if(t[i][j]!=0) r--; }
for(i=0;i<=m+1;i++) for(j=0;j<=n+1;j++)
tmp[i][j]=t[i][j];
while(1){ d++; flag=false;
for(i=1;i<=m;i++) for(j=1;j<=n;j++)
if(t[i][j]==1) for(k=0;k<4;k++)
if(tmp[i+dx[k]][j+dy[k]]==0){
tmp[i+dx[k]][j+dy[k]]=1;
flag=true; r--; }
for(i=1;i<=m;i++) for(j=1;j<=n;j++) t[i][j]=tmp[i][j];
if(!flag||r==0) break;
}
if(r) printf("-1");
else printf("%d",d);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
9056 KB |
Output is correct |
2 |
Correct |
0 ms |
9056 KB |
Output is correct |
3 |
Correct |
0 ms |
9056 KB |
Output is correct |
4 |
Correct |
0 ms |
9056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
9056 KB |
Output is correct |
2 |
Correct |
0 ms |
9056 KB |
Output is correct |
3 |
Correct |
0 ms |
9056 KB |
Output is correct |
4 |
Correct |
0 ms |
9056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
9056 KB |
Output is correct |
2 |
Correct |
12 ms |
9056 KB |
Output is correct |
3 |
Correct |
0 ms |
9056 KB |
Output is correct |
4 |
Correct |
16 ms |
9056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9056 KB |
Output is correct |
2 |
Correct |
8 ms |
9056 KB |
Output is correct |
3 |
Correct |
0 ms |
9056 KB |
Output is correct |
4 |
Correct |
0 ms |
9056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
9056 KB |
Output is correct |
2 |
Correct |
0 ms |
9056 KB |
Output is correct |
3 |
Correct |
16 ms |
9056 KB |
Output is correct |
4 |
Correct |
48 ms |
9056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9056 KB |
Output is correct |
2 |
Execution timed out |
1000 ms |
9052 KB |
Program timed out |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
724 ms |
9056 KB |
Output is correct |
2 |
Execution timed out |
1000 ms |
9052 KB |
Program timed out |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
596 ms |
9056 KB |
Output is correct |
2 |
Correct |
352 ms |
9056 KB |
Output is correct |
3 |
Correct |
32 ms |
9056 KB |
Output is correct |
4 |
Correct |
132 ms |
9056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
600 ms |
9056 KB |
Output is correct |
2 |
Execution timed out |
1000 ms |
9052 KB |
Program timed out |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
9056 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |