-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitmap.cpp
More file actions
90 lines (87 loc) · 1.88 KB
/
bitmap.cpp
File metadata and controls
90 lines (87 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
/*void init(int n,int m,int vis[n][m])
{
for(int i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
vis[i][j]=0;
}
}
}*/
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m,i,j;
int t,q,left,right;
cin>>t;
string s;
while(t--)
{
cin>>n>>m;
queue <pair <int,int> > q;
int arr[n][m];
int vis[n][m];
//init(n,m,vis);
for(i=0;i<n;i++)
{
cin>>s;
for(j=0;j<m;j++)
{
arr[i][j]=s[j]-'0';
if(arr[i][j]==1)
{
q.push(make_pair(i,j));
}
}
}
pair <int,int> fro;
/*while(!q.empty())
{
fro=q.front();
left=fro.first;
right=fro.second;
cout<<left<<" "<<right<<endl;
q.pop();
}*/
while(!q.empty())
{
fro=q.front();
left=fro.first;
right=fro.second;
//cout<<left<<" "<<right<<endl;
if( (left+1)<n && arr[left+1][right]==0)
{
arr[left+1][right]=arr[left][right]+1;
q.push(make_pair(left+1,right));
}
if((right+1)<m && arr[left][right+1]==0 )
{
arr[left][right+1]=arr[left][right]+1;
q.push(make_pair(left,right+1));
}
if((left-1)>=0 && arr[left-1][right]==0 )
{
arr[left-1][right]=arr[left][right]+1;
q.push(make_pair(left-1,right));
}
if( (right-1)>=0 && arr[left][right-1]==0 )
{
arr[left][right-1]=arr[left][right]+1;
q.push(make_pair(left,right-1));
}
q.pop();
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cout<<--(arr[i][j])<<" ";
}
cout<<endl;
}
}
return 0;
}