BOJ : https://www.acmicpc.net/problem/2636
github : https://github.com/junho0956/Algorithm/blob/master/2636/2636/%EC%86%8C%EC%8A%A4.cpp
제가 구현 실력이 부족한거겠지만
정올 초등부(3번) 수준이 이정도라니 정말 놀랐습니다ㅠㅠ
중간에 구멍이 뚫리면 공기와 만난다는 점만 고려해주셔서 구현해주시면 될 것 같습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> pii;
queue<pair<pii, int> > q;
queue<pii> delq;
int arr[101][101];
bool visit[101][101];
int my[4] = { -1,1,0,0 };
int mx[4] = { 0,0,1,-1 };
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> arr[i][j];
if (arr[i][j]) q.push({ {i,j},0 });
}
}
queue<pii> hole;
int y = hole.front().first;
int x = hole.front().second;
hole.pop();
if (visit[y][x]) continue;
visit[y][x] = true;
arr[y][x] = 2;
for (int i = 0; i < 4; i++) {
int yy = y + my[i];
int xx = x + mx[i];
if (yy >= 0 && yy < n && xx >= 0 && xx < m && !visit[yy][xx] && !arr[yy][xx]) {
hole.push({ yy,xx });
}
}
}
int time = 0;
int ans;
while (1) {
bool finish = true;
int cnt = 0;
while (!q.empty()) {
int intime = q.front().second;
if (intime != time) break;
q.pop();
bool check = true;
for (int i = 0; i < 4; i++) {
int yy = y + my[i];
int xx = x + mx[i];
if (yy >= 0 && yy < n && xx>=0 && xx < m && arr[yy][xx] == 2) {
check = false;
break;
}
}
else q.push({ {y,x},time + 1 }), finish = false;
}
int y = delq.front().first;
int x = delq.front().second;
delq.pop();
arr[y][x] = 2;
for (int i = 0; i < 4; i++) {
int yy = y + my[i];
int xx = x + mx[i];
}
cnt++;
}
int y = hole.front().first;
int x = hole.front().second;
hole.pop();
if (visit[y][x]) continue;
visit[y][x] = true;
arr[y][x] = 2;
for (int i = 0; i < 4; i++) {
int yy = y + my[i];
int xx = x + mx[i];
}
}
time++;
if (finish) {
ans = cnt;
break;
}
}
cout << time << " " << ans;
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'algorithm > BOJ' 카테고리의 다른 글
BOJ 2011번 암호코드 (0) | 2020.02.13 |
---|---|
BOJ 2638번 치즈 (0) | 2020.02.13 |
BOJ 13711번 LCS 4 (0) | 2020.02.12 |
BOJ 1958번 LCS 3 (0) | 2020.02.12 |
BOJ 9252번 LCS2 (0) | 2020.02.12 |