# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
824409 |
2023-08-14T05:38:26 Z |
이동현(#10361) |
Sirtet (CCO19_day1problem2) |
C++17 |
|
2000 ms |
53216 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;
int wx[4] = {-1, 0, 1, 0};
int wy[4] = {0, 1, 0, -1};
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<string> a(n);
for(int i = 0; i < n; ++i){
cin >> a[i];
}
vector<vector<int>> col(n, vector<int>(m, -1));
int cn = 0;
auto dfs = [&](auto&&self, int x, int y)->void{
col[x][y] = cn;
for(int i = 0; i < 4; ++i){
int nx = x + wx[i], ny = y + wy[i];
if(nx >= 0 && nx < n && ny >= 0 && ny < m && a[nx][ny] == '#' && col[nx][ny] == -1){
self(self, nx, ny);
}
}
};
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
if(a[i][j] == '.' || col[i][j] != -1){
continue;
}
dfs(dfs, i, j);
++cn;
}
}
vector<vector<array<int, 2>>> way(cn);
vector<int> mn(cn, (int)1e9);
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
if(col[i][j] != -1){
mn[col[i][j]] = min(mn[col[i][j]], n - i - 1);
}
}
}
for(int j = 0; j < m; ++j){
int lst = n;
for(int i = n - 1; i >= 0; --i){
if(col[i][j] == -1) continue;
if(lst != n && col[i][j] != col[lst][j]){
way[col[lst][j]].push_back({col[i][j], mn[col[i][j]] - mn[col[lst][j]] - (lst - i - 1)});
// cout << lst << ' ' << i << ' ' << mn[col[i][j]] - mn[col[lst][j]] - (lst - i - 1) << endl;
}
lst = i;
}
}
vector<int> dist(cn, 0), inq(cn, 1);
queue<int> que;
for(int i = 0; i < cn; ++i){
que.push(i);
}
while(!que.empty()){
int now = que.front();
que.pop();
inq[now] = 0;
// cout << now << ' ' << dist[now] << endl;
for(auto&[nxt, dis]:way[now]){
// cout << dist[now] << ' ' << nxt << ' ' << dist[nxt] << endl;
if(dist[now] + dis > dist[nxt]){
dist[nxt] = dist[now] + dis;
if(!inq[nxt]){
inq[nxt] = 1;
que.push(nxt);
}
}
}
}
// for(int i = 0; i < cn; ++i){
// cout << dist[i] << endl;
// }
vector<vector<char>> ans(n, vector<char>(m, '.'));
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
if(col[i][j] == -1){
continue;
}
ans[n - dist[col[i][j]] - 1 - (n - mn[col[i][j]] - 1 - i)][j] = '#';
}
}
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
cout << ans[i][j];
}
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
264 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
0 ms |
320 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2073 ms |
53216 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
264 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
0 ms |
320 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
320 KB |
Output is correct |
24 |
Execution timed out |
2073 ms |
53216 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |