답안 #824468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824468 2023-08-14T06:39:43 Z 박영우(#10362) Sirtet (CCO19_day1problem2) C++17
25 / 25
177 ms 127108 KB
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 1001010
#define MAXS 20
#define INF 1000000000
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 1000000007
vector<vector<int>> mp, col, ans;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int N, M;
void dfs(int x, int y, int c) {
	if (x <= 0 || y <= 0 || x > N || y > M) return;
	if (col[x][y]) return;
	if (!mp[x][y]) return;
	col[x][y] = c;
	for (int k = 0; k < 4; k++) dfs(x + dx[k], y + dy[k], c);
}
int dist[MAX];
int vis[MAX];
vector<pii> adj[MAX];
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> N >> M;
	ans = col = mp = vector<vector<int>>(N + 2, vector<int>(M + 2));
	int i, j;
	for (i = 1; i <= N; i++) {
		string s;
		cin >> s;
		for (j = 1; j <= M; j++) mp[i][j] = s[j - 1] == '#';
	}
	reverse(mp.begin(), mp.end());
	int cnt = 0;
	for (i = 1; i <= N; i++) for (j = 1; j <= M; j++) if (mp[i][j] && !col[i][j]) dfs(i, j, ++cnt);
	int pv;
	for (i = 1; i <= M; i++) {
		pv = 0;
		for (j = 1; j <= N; j++) {
			if (mp[j][i]) {
				adj[col[pv][i]].emplace_back(col[j][i], j - pv - 1);
				pv = j;
			}
		}
	}
	for (i = 1; i <= cnt; i++) dist[i] = 1010101010;
	priority_queue<pii, vector<pii>, greater<pii>> pq;
	pq.emplace(0, 0);
	while (pq.size()) {
		int t = pq.top().second;
		pq.pop();
		if (vis[t]) continue;
		vis[t] = 1;
		for (auto& [v, c] : adj[t]) {
			if (vis[v]) continue;
			if (dist[v] > dist[t] + c) {
				dist[v] = dist[t] + c;
				pq.emplace(dist[v], v);
			}
		}
	}
	for (i = 1; i <= N; i++) for (j = 1; j <= M; j++) if (col[i][j]) ans[i - dist[col[i][j]]][j] = 1;
	reverse(ans.begin(), ans.end());
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= M; j++) cout << (ans[i][j] ? '#' : '.');
		cout << ln;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23848 KB Output is correct
3 Correct 13 ms 23844 KB Output is correct
4 Correct 11 ms 23832 KB Output is correct
5 Correct 10 ms 23852 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 12 ms 23844 KB Output is correct
8 Correct 11 ms 23764 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 11 ms 23764 KB Output is correct
11 Correct 11 ms 23836 KB Output is correct
12 Correct 11 ms 23892 KB Output is correct
13 Correct 12 ms 23824 KB Output is correct
14 Correct 14 ms 23996 KB Output is correct
15 Correct 11 ms 23892 KB Output is correct
16 Correct 11 ms 23808 KB Output is correct
17 Correct 11 ms 23816 KB Output is correct
18 Correct 13 ms 23844 KB Output is correct
19 Correct 12 ms 23880 KB Output is correct
20 Correct 12 ms 23840 KB Output is correct
21 Correct 11 ms 23892 KB Output is correct
22 Correct 12 ms 23876 KB Output is correct
23 Correct 11 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 177 ms 113036 KB Output is correct
2 Correct 177 ms 119464 KB Output is correct
3 Correct 166 ms 118948 KB Output is correct
4 Correct 156 ms 112324 KB Output is correct
5 Correct 172 ms 127108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23848 KB Output is correct
3 Correct 13 ms 23844 KB Output is correct
4 Correct 11 ms 23832 KB Output is correct
5 Correct 10 ms 23852 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 12 ms 23844 KB Output is correct
8 Correct 11 ms 23764 KB Output is correct
9 Correct 11 ms 23764 KB Output is correct
10 Correct 11 ms 23764 KB Output is correct
11 Correct 11 ms 23836 KB Output is correct
12 Correct 11 ms 23892 KB Output is correct
13 Correct 12 ms 23824 KB Output is correct
14 Correct 14 ms 23996 KB Output is correct
15 Correct 11 ms 23892 KB Output is correct
16 Correct 11 ms 23808 KB Output is correct
17 Correct 11 ms 23816 KB Output is correct
18 Correct 13 ms 23844 KB Output is correct
19 Correct 12 ms 23880 KB Output is correct
20 Correct 12 ms 23840 KB Output is correct
21 Correct 11 ms 23892 KB Output is correct
22 Correct 12 ms 23876 KB Output is correct
23 Correct 11 ms 23764 KB Output is correct
24 Correct 177 ms 113036 KB Output is correct
25 Correct 177 ms 119464 KB Output is correct
26 Correct 166 ms 118948 KB Output is correct
27 Correct 156 ms 112324 KB Output is correct
28 Correct 172 ms 127108 KB Output is correct
29 Correct 50 ms 46764 KB Output is correct
30 Correct 49 ms 45136 KB Output is correct
31 Correct 50 ms 48084 KB Output is correct
32 Correct 33 ms 35964 KB Output is correct
33 Correct 55 ms 49356 KB Output is correct
34 Correct 54 ms 48260 KB Output is correct
35 Correct 70 ms 45736 KB Output is correct
36 Correct 50 ms 42120 KB Output is correct
37 Correct 51 ms 43384 KB Output is correct
38 Correct 47 ms 45024 KB Output is correct
39 Correct 41 ms 38568 KB Output is correct
40 Correct 56 ms 41800 KB Output is correct
41 Correct 63 ms 45732 KB Output is correct
42 Correct 63 ms 52400 KB Output is correct
43 Correct 47 ms 39916 KB Output is correct
44 Correct 48 ms 41632 KB Output is correct
45 Correct 38 ms 37356 KB Output is correct
46 Correct 51 ms 43556 KB Output is correct
47 Correct 50 ms 42896 KB Output is correct
48 Correct 53 ms 42328 KB Output is correct
49 Correct 51 ms 40844 KB Output is correct
50 Correct 66 ms 60360 KB Output is correct
51 Correct 82 ms 53640 KB Output is correct
52 Correct 114 ms 60092 KB Output is correct
53 Correct 91 ms 52992 KB Output is correct
54 Correct 105 ms 58620 KB Output is correct
55 Correct 118 ms 46840 KB Output is correct
56 Correct 106 ms 45844 KB Output is correct
57 Correct 53 ms 39220 KB Output is correct
58 Correct 69 ms 41208 KB Output is correct
59 Correct 97 ms 44780 KB Output is correct
60 Correct 59 ms 40232 KB Output is correct
61 Correct 44 ms 39876 KB Output is correct
62 Correct 50 ms 39424 KB Output is correct
63 Correct 123 ms 67980 KB Output is correct
64 Correct 105 ms 56700 KB Output is correct
65 Correct 109 ms 62020 KB Output is correct
66 Correct 134 ms 56268 KB Output is correct
67 Correct 81 ms 67276 KB Output is correct
68 Correct 56 ms 46404 KB Output is correct
69 Correct 89 ms 73824 KB Output is correct
70 Correct 51 ms 43448 KB Output is correct