#include<bits/stdc++.h>
#define int long long
#define Get(i,j) ((i-1)*m+j)
#define quick ios::sync_with_stdio(0);cin.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define repd(x,a,b) for(int x=a;x>=b;x--)
#define lowbit(x) (x&-x)
#define sz(x) (int)(x.size())
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define mp make_pair
#define eb emplace_back
using namespace std;
typedef pair<int,int> pii;
void debug(){
cout<<"\n";
}
template <class T,class ... U >
void debug(T a, U ... b){
cout<<a<<" ",debug(b...);
}
const int N=1e6+7;
const int INF=1e18;
int lp[N];
int lk[N];
int p[N];
int sz[N];
int add[N];
void init(int n){
rep(i,1,n) p[i]=i,sz[i]=1,add[i]=INF,sz[i]=1;
}
int fp(int x){
if(p[x]!=x) p[x]=fp(p[x]);
return p[x];
}
void Union(int a,int b){
a=fp(a),b=fp(b);
if(sz[a]<sz[b]) swap(a,b);
p[b]=a;
sz[a]+=sz[b];
}
signed main(){
quick
double st=clock();
int n,m;
cin>>n>>m;
vector<vector<bool> > v(n+5,vector<bool>(m+1));
vector<vector<int> > f(n+5,vector<int>(m+1));
init(n*m);
rep(i,1,n){
rep(j,1,m){
char c;
cin>>c;
v[i][j]=(c=='#');
}
}
rep(i,1,n){
rep(j,1,m){
if(!v[i][j]) continue;
if(v[i-1][j]) Union(Get(i,j),Get(i-1,j));
if(v[i][j-1]) Union(Get(i,j),Get(i,j-1));
}
}
vector<pii> traverse;
rep(t,1,4){
rep(i,1,m) lp[i]=n+1,lk[i]=0;
repd(i,n,1){
rep(j,1,m) {
if(!v[i][j]) continue;
int k=fp(Get(i,j));
add[k]=min(add[k],lp[j]+add[lk[j]]-i-1);
lp[j]=i,lk[j]=k;
}
}
}
vector<vector<bool> > ans(n+5,vector<bool>(m+1));
rep(i,1,n){
rep(j,1,m){
if(v[i][j]){
int k=fp(Get(i,j));
ans[i+add[k]][j]=1;
}
}
}
rep(i,1,n){
rep(j,1,m) cout<<".#"[ans[i][j]];cout<<"\n";
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:5:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
5 | #define rep(x,a,b) for(int x=a;x<=b;x++)
| ^~~
Main.cpp:89:9: note: in expansion of macro 'rep'
89 | rep(j,1,m) cout<<".#"[ans[i][j]];cout<<"\n";
| ^~~
Main.cpp:89:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
89 | rep(j,1,m) cout<<".#"[ans[i][j]];cout<<"\n";
| ^~~~
Main.cpp:89:52: error: expected '}' at end of input
89 | rep(j,1,m) cout<<".#"[ans[i][j]];cout<<"\n";
| ^
Main.cpp:88:15: note: to match this '{'
88 | rep(i,1,n){
| ^
Main.cpp:45:12: warning: unused variable 'st' [-Wunused-variable]
45 | double st=clock();
| ^~
Main.cpp:89:52: error: expected '}' at end of input
89 | rep(j,1,m) cout<<".#"[ans[i][j]];cout<<"\n";
| ^
Main.cpp:43:14: note: to match this '{'
43 | signed main(){
| ^