#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;
while((clock()-st)/CLOCKS_PER_SEC<=1.3){
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";
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1300 ms |
340 KB |
Output is correct |
2 |
Correct |
1300 ms |
344 KB |
Output is correct |
3 |
Correct |
1300 ms |
344 KB |
Output is correct |
4 |
Correct |
1300 ms |
340 KB |
Output is correct |
5 |
Correct |
1301 ms |
344 KB |
Output is correct |
6 |
Correct |
1300 ms |
344 KB |
Output is correct |
7 |
Correct |
1300 ms |
344 KB |
Output is correct |
8 |
Correct |
1300 ms |
340 KB |
Output is correct |
9 |
Correct |
1300 ms |
344 KB |
Output is correct |
10 |
Correct |
1300 ms |
344 KB |
Output is correct |
11 |
Correct |
1301 ms |
404 KB |
Output is correct |
12 |
Correct |
1301 ms |
412 KB |
Output is correct |
13 |
Correct |
1301 ms |
416 KB |
Output is correct |
14 |
Correct |
1301 ms |
412 KB |
Output is correct |
15 |
Correct |
1301 ms |
412 KB |
Output is correct |
16 |
Correct |
1301 ms |
420 KB |
Output is correct |
17 |
Correct |
1301 ms |
416 KB |
Output is correct |
18 |
Correct |
1301 ms |
340 KB |
Output is correct |
19 |
Correct |
1301 ms |
412 KB |
Output is correct |
20 |
Correct |
1301 ms |
468 KB |
Output is correct |
21 |
Correct |
1301 ms |
416 KB |
Output is correct |
22 |
Correct |
1301 ms |
416 KB |
Output is correct |
23 |
Correct |
1300 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1373 ms |
124520 KB |
Output is correct |
2 |
Correct |
1368 ms |
124640 KB |
Output is correct |
3 |
Correct |
1372 ms |
124516 KB |
Output is correct |
4 |
Correct |
1368 ms |
124544 KB |
Output is correct |
5 |
Correct |
1375 ms |
124512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1300 ms |
340 KB |
Output is correct |
2 |
Correct |
1300 ms |
344 KB |
Output is correct |
3 |
Correct |
1300 ms |
344 KB |
Output is correct |
4 |
Correct |
1300 ms |
340 KB |
Output is correct |
5 |
Correct |
1301 ms |
344 KB |
Output is correct |
6 |
Correct |
1300 ms |
344 KB |
Output is correct |
7 |
Correct |
1300 ms |
344 KB |
Output is correct |
8 |
Correct |
1300 ms |
340 KB |
Output is correct |
9 |
Correct |
1300 ms |
344 KB |
Output is correct |
10 |
Correct |
1300 ms |
344 KB |
Output is correct |
11 |
Correct |
1301 ms |
404 KB |
Output is correct |
12 |
Correct |
1301 ms |
412 KB |
Output is correct |
13 |
Correct |
1301 ms |
416 KB |
Output is correct |
14 |
Correct |
1301 ms |
412 KB |
Output is correct |
15 |
Correct |
1301 ms |
412 KB |
Output is correct |
16 |
Correct |
1301 ms |
420 KB |
Output is correct |
17 |
Correct |
1301 ms |
416 KB |
Output is correct |
18 |
Correct |
1301 ms |
340 KB |
Output is correct |
19 |
Correct |
1301 ms |
412 KB |
Output is correct |
20 |
Correct |
1301 ms |
468 KB |
Output is correct |
21 |
Correct |
1301 ms |
416 KB |
Output is correct |
22 |
Correct |
1301 ms |
416 KB |
Output is correct |
23 |
Correct |
1300 ms |
336 KB |
Output is correct |
24 |
Correct |
1373 ms |
124520 KB |
Output is correct |
25 |
Correct |
1368 ms |
124640 KB |
Output is correct |
26 |
Correct |
1372 ms |
124516 KB |
Output is correct |
27 |
Correct |
1368 ms |
124544 KB |
Output is correct |
28 |
Correct |
1375 ms |
124512 KB |
Output is correct |
29 |
Correct |
1321 ms |
33420 KB |
Output is correct |
30 |
Correct |
1322 ms |
33420 KB |
Output is correct |
31 |
Correct |
1321 ms |
32028 KB |
Output is correct |
32 |
Correct |
1312 ms |
19260 KB |
Output is correct |
33 |
Correct |
1330 ms |
33304 KB |
Output is correct |
34 |
Correct |
1324 ms |
34144 KB |
Output is correct |
35 |
Correct |
1323 ms |
34140 KB |
Output is correct |
36 |
Correct |
1323 ms |
34160 KB |
Output is correct |
37 |
Correct |
1324 ms |
34144 KB |
Output is correct |
38 |
Correct |
1323 ms |
34144 KB |
Output is correct |
39 |
Correct |
1321 ms |
34400 KB |
Output is correct |
40 |
Correct |
1322 ms |
34048 KB |
Output is correct |
41 |
Correct |
1325 ms |
34044 KB |
Output is correct |
42 |
Correct |
1322 ms |
34032 KB |
Output is correct |
43 |
Correct |
1322 ms |
34052 KB |
Output is correct |
44 |
Correct |
1323 ms |
34124 KB |
Output is correct |
45 |
Correct |
1321 ms |
34052 KB |
Output is correct |
46 |
Correct |
1331 ms |
34044 KB |
Output is correct |
47 |
Correct |
1323 ms |
34048 KB |
Output is correct |
48 |
Correct |
1325 ms |
35920 KB |
Output is correct |
49 |
Correct |
1323 ms |
34052 KB |
Output is correct |
50 |
Correct |
1325 ms |
32896 KB |
Output is correct |
51 |
Correct |
1337 ms |
51748 KB |
Output is correct |
52 |
Correct |
1343 ms |
51744 KB |
Output is correct |
53 |
Correct |
1340 ms |
51744 KB |
Output is correct |
54 |
Correct |
1339 ms |
51740 KB |
Output is correct |
55 |
Correct |
1338 ms |
35408 KB |
Output is correct |
56 |
Correct |
1330 ms |
35408 KB |
Output is correct |
57 |
Correct |
1323 ms |
35408 KB |
Output is correct |
58 |
Correct |
1324 ms |
35400 KB |
Output is correct |
59 |
Correct |
1329 ms |
34048 KB |
Output is correct |
60 |
Correct |
1323 ms |
34044 KB |
Output is correct |
61 |
Correct |
1323 ms |
39496 KB |
Output is correct |
62 |
Correct |
1323 ms |
36804 KB |
Output is correct |
63 |
Correct |
1324 ms |
34056 KB |
Output is correct |
64 |
Correct |
1325 ms |
36724 KB |
Output is correct |
65 |
Correct |
1328 ms |
42636 KB |
Output is correct |
66 |
Correct |
1322 ms |
34048 KB |
Output is correct |
67 |
Correct |
1340 ms |
71648 KB |
Output is correct |
68 |
Correct |
1330 ms |
48752 KB |
Output is correct |
69 |
Correct |
1341 ms |
71536 KB |
Output is correct |
70 |
Correct |
1327 ms |
43596 KB |
Output is correct |