-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_11559.cpp
More file actions
72 lines (67 loc) · 1.31 KB
/
BOJ_11559.cpp
File metadata and controls
72 lines (67 loc) · 1.31 KB
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
#include <bits/stdc++.h>
using namespace std;
string s;
char arr[12][6];
int visited[12][6], ret;
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
vector<pair<int, int>> v;
void solve(int row, int col, char c) {
v.push_back({ row, col });
visited[row][col] = 1;
for (int k = 0; k < 4; k++) {
int nRow = row + dy[k];
int nCol = col + dx[k];
if (nRow < 0 || nCol < 0 || nRow >= 12 || nCol >= 6 || visited[nRow][nCol]) continue;
if (arr[nRow][nCol] == c) {
solve(nRow, nCol, c);
}
}
}
void arrange() {
for (int i = 0; i < 6; i++) {
int p = 11;
while (p >= 0) {
if (arr[p][i] == '*') {
for (int k = p; k >= 1; k--) {
arr[k][i] = arr[k - 1][i];
}
arr[0][i] = '.';
}
else p--;
}
}
}
int main() {
for (int i = 0; i < 12; i++) {
cin >> s;
for (int j = 0; j < 6; j++) {
arr[i][j] = s[j];
}
}
bool bomb = true;
while (bomb) {
memset(visited, 0, sizeof(visited));
bomb = false;
for (int i = 11; i >= 0; i--) {
for (int j = 0; j < 6; j++) {
if (arr[i][j] != '.' && !visited[i][j]) {
v.clear();
solve(i, j, arr[i][j]);
if (v.size() >= 4) {
for (auto a : v) {
arr[a.first][a.second] = '*';
}
bomb = true;
}
}
}
}
if (bomb) {
ret++;
arrange();
}
}
cout << ret << "\n";
return 0;
}