#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
using u128 = __uint128_t;
const int x[4] = {1, 0, -1, 0};
const int y[4] = {0, -1, 0, 1};
const ll mod =1e9 + 7;
const int mxn = 1e6 + 5, mxq = 1e5 + 5, sq = 300, mxm = 1e6 + 5;
//const int base = (1 <<18);
const ll inf = 1e9 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
// <3;
int n, m;
vt<vt<char>>v;
vt<vt<int>>comp;
int idcomp = 0;
int in[mxn + 1], dp[mxn + 1];
vt<pii>adj[mxn + 1];
bool inside(int cx, int cy){
return(cx >= 0 && cy >= 0 && cx < n && cy < m);
}
void dfs(int cx, int cy){
comp[cx][cy] = idcomp;
for(int i = 0; i < 4; i++){
int px = cx + x[i], py = cy + y[i];
if(inside(px, py) && !comp[px][py] && v[px][py] == '#')dfs(px, py);
}
}
void solve(){
cin >> n >> m;
v.resize(n, vt<char>(m));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> v[i][j];
}
}
comp.resize(n + 1, vt<int>(m, 0));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(comp[i][j] == 0 && v[i][j] == '#'){
idcomp++;
dfs(i, j);
}
}
}
for(int i = 0; i < m; i++){
int last = n;
for(int j = n - 1; j >= 0; j--){
if(v[j][i] == '#'){
if(comp[last][i] != comp[j][i]){
adj[comp[last][i]].pb(mpp(comp[j][i], last - j - 1)); in[comp[j][i]]++;
}
last = j;
}
}
}
priority_queue<pii, vt<pii>, greater<pii>>pq;
for(int i = 1; i <= idcomp; i++)dp[i] = inf;
pq.push(mpp(dp[0], 0));
while(!pq.empty()){
auto [dd, u] = pq.top(); pq.pop();
if(dp[u] != dd)continue;
for(auto [v, w]: adj[u]){
if(dp[v] > dp[u] + w){
dp[v] = dp[u] + w;
pq.push(mpp(dp[v], v));
}
}
}
vt<vt<char>>res(n, vt<char>(m));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
res[i][j] = '.';
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(v[i][j] == '#'){
int offset = dp[comp[i][j]];
res[i + offset][j] = '#';
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << res[i][j];
}
cout << "\n";
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("SODOCLA.INP", "r", stdin);
//freopen("SODOCLA.INP", "w", stdout);
int tt; tt = 1;
while(tt--){
solve();
}
return(0);
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:81:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
81 | auto [dd, u] = pq.top(); pq.pop();
| ^
Main.cpp:83:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
83 | for(auto [v, w]: adj[u]){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
27228 KB |
Output is correct |
2 |
Correct |
6 ms |
27240 KB |
Output is correct |
3 |
Correct |
6 ms |
27228 KB |
Output is correct |
4 |
Correct |
6 ms |
27228 KB |
Output is correct |
5 |
Correct |
6 ms |
27308 KB |
Output is correct |
6 |
Correct |
6 ms |
27228 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
8 |
Correct |
6 ms |
27228 KB |
Output is correct |
9 |
Correct |
6 ms |
27228 KB |
Output is correct |
10 |
Correct |
6 ms |
27224 KB |
Output is correct |
11 |
Correct |
7 ms |
27228 KB |
Output is correct |
12 |
Correct |
6 ms |
27308 KB |
Output is correct |
13 |
Correct |
6 ms |
27228 KB |
Output is correct |
14 |
Correct |
6 ms |
27228 KB |
Output is correct |
15 |
Correct |
7 ms |
27228 KB |
Output is correct |
16 |
Correct |
6 ms |
27228 KB |
Output is correct |
17 |
Correct |
6 ms |
27228 KB |
Output is correct |
18 |
Correct |
6 ms |
27304 KB |
Output is correct |
19 |
Correct |
10 ms |
27228 KB |
Output is correct |
20 |
Correct |
6 ms |
27228 KB |
Output is correct |
21 |
Correct |
7 ms |
27228 KB |
Output is correct |
22 |
Correct |
6 ms |
27228 KB |
Output is correct |
23 |
Correct |
6 ms |
27228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
115540 KB |
Output is correct |
2 |
Correct |
141 ms |
121680 KB |
Output is correct |
3 |
Correct |
128 ms |
112724 KB |
Output is correct |
4 |
Correct |
135 ms |
114000 KB |
Output is correct |
5 |
Correct |
154 ms |
132180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
27228 KB |
Output is correct |
2 |
Correct |
6 ms |
27240 KB |
Output is correct |
3 |
Correct |
6 ms |
27228 KB |
Output is correct |
4 |
Correct |
6 ms |
27228 KB |
Output is correct |
5 |
Correct |
6 ms |
27308 KB |
Output is correct |
6 |
Correct |
6 ms |
27228 KB |
Output is correct |
7 |
Correct |
6 ms |
27228 KB |
Output is correct |
8 |
Correct |
6 ms |
27228 KB |
Output is correct |
9 |
Correct |
6 ms |
27228 KB |
Output is correct |
10 |
Correct |
6 ms |
27224 KB |
Output is correct |
11 |
Correct |
7 ms |
27228 KB |
Output is correct |
12 |
Correct |
6 ms |
27308 KB |
Output is correct |
13 |
Correct |
6 ms |
27228 KB |
Output is correct |
14 |
Correct |
6 ms |
27228 KB |
Output is correct |
15 |
Correct |
7 ms |
27228 KB |
Output is correct |
16 |
Correct |
6 ms |
27228 KB |
Output is correct |
17 |
Correct |
6 ms |
27228 KB |
Output is correct |
18 |
Correct |
6 ms |
27304 KB |
Output is correct |
19 |
Correct |
10 ms |
27228 KB |
Output is correct |
20 |
Correct |
6 ms |
27228 KB |
Output is correct |
21 |
Correct |
7 ms |
27228 KB |
Output is correct |
22 |
Correct |
6 ms |
27228 KB |
Output is correct |
23 |
Correct |
6 ms |
27228 KB |
Output is correct |
24 |
Correct |
134 ms |
115540 KB |
Output is correct |
25 |
Correct |
141 ms |
121680 KB |
Output is correct |
26 |
Correct |
128 ms |
112724 KB |
Output is correct |
27 |
Correct |
135 ms |
114000 KB |
Output is correct |
28 |
Correct |
154 ms |
132180 KB |
Output is correct |
29 |
Correct |
48 ms |
42324 KB |
Output is correct |
30 |
Correct |
50 ms |
42324 KB |
Output is correct |
31 |
Correct |
47 ms |
46164 KB |
Output is correct |
32 |
Correct |
32 ms |
34908 KB |
Output is correct |
33 |
Correct |
51 ms |
44116 KB |
Output is correct |
34 |
Correct |
55 ms |
42320 KB |
Output is correct |
35 |
Correct |
52 ms |
41300 KB |
Output is correct |
36 |
Correct |
46 ms |
38996 KB |
Output is correct |
37 |
Correct |
47 ms |
37712 KB |
Output is correct |
38 |
Correct |
51 ms |
41300 KB |
Output is correct |
39 |
Correct |
40 ms |
35308 KB |
Output is correct |
40 |
Correct |
47 ms |
35668 KB |
Output is correct |
41 |
Correct |
50 ms |
39060 KB |
Output is correct |
42 |
Correct |
57 ms |
47748 KB |
Output is correct |
43 |
Correct |
45 ms |
35392 KB |
Output is correct |
44 |
Correct |
46 ms |
35688 KB |
Output is correct |
45 |
Correct |
38 ms |
35156 KB |
Output is correct |
46 |
Correct |
58 ms |
37200 KB |
Output is correct |
47 |
Correct |
45 ms |
38996 KB |
Output is correct |
48 |
Correct |
48 ms |
36944 KB |
Output is correct |
49 |
Correct |
50 ms |
35540 KB |
Output is correct |
50 |
Correct |
63 ms |
57168 KB |
Output is correct |
51 |
Correct |
70 ms |
47956 KB |
Output is correct |
52 |
Correct |
91 ms |
48700 KB |
Output is correct |
53 |
Correct |
68 ms |
48980 KB |
Output is correct |
54 |
Correct |
95 ms |
53632 KB |
Output is correct |
55 |
Correct |
104 ms |
42580 KB |
Output is correct |
56 |
Correct |
94 ms |
42424 KB |
Output is correct |
57 |
Correct |
51 ms |
36432 KB |
Output is correct |
58 |
Correct |
57 ms |
36248 KB |
Output is correct |
59 |
Correct |
93 ms |
41516 KB |
Output is correct |
60 |
Correct |
57 ms |
35340 KB |
Output is correct |
61 |
Correct |
41 ms |
35788 KB |
Output is correct |
62 |
Correct |
51 ms |
36172 KB |
Output is correct |
63 |
Correct |
112 ms |
66444 KB |
Output is correct |
64 |
Correct |
109 ms |
54288 KB |
Output is correct |
65 |
Correct |
105 ms |
60492 KB |
Output is correct |
66 |
Correct |
121 ms |
54868 KB |
Output is correct |
67 |
Correct |
71 ms |
62628 KB |
Output is correct |
68 |
Correct |
52 ms |
45688 KB |
Output is correct |
69 |
Correct |
73 ms |
67536 KB |
Output is correct |
70 |
Correct |
46 ms |
41252 KB |
Output is correct |