공기에 노출된 부분을 bfs로 구하고, 그 정보를 이용해 치즈를 녹인다.
이 과정을 치즈가 전부 녹아내릴때 까지 반복하면 된다.
근데 진짜 치즈 내부에는 구멍이 있어도 상관없나??
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0), cin.tie(0)
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool arr[101][101], exposed[101][101];
int n, m;
void input() {
fastio;
cin >> n >> m;
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j)
cin >> arr[i][j];
}
int bfs() {
int ret = 0;
memset(exposed, false, sizeof(exposed));
exposed[0][0] = true;
queue<pair<int, int> > q;
q.push({0, 0});
while(!q.empty()) {
auto [x, y] = q.front(); q.pop();
ret++;
for(int i = 0; i < 4; ++i) {
int nx = x + dx[i], ny = y + dy[i];
if(nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
if(exposed[nx][ny] || arr[nx][ny]) continue;
exposed[nx][ny] = true;
q.push({nx, ny});
}
}
return ret;
}
void melt() {
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) {
if(!arr[i][j]) continue;
int cnt = 0;
for(int k = 0; k < 4; ++k) {
if(exposed[i+dx[k]][j+dy[k]]) cnt++;
if(cnt > 1) break;
}
if(cnt > 1) arr[i][j] = 0;
}
}
}
int main() {
input();
int ans = 0;
while(bfs() < n*m) {
melt();
ans++;
}
cout << ans;
}
백준 16434 드래곤 앤 던전 혼내주기 (0) | 2021.07.26 |
---|---|
백준 1238 파티 혼내주기 (0) | 2021.07.26 |
백준 11779 최소비용 구하기 2 (0) | 2021.07.26 |
백준 3665 최종 순위 혼내주기 (0) | 2021.07.26 |
백준 14500 테트로미노 혼내주기 (0) | 2021.07.26 |
댓글 영역