-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11559.cpp
95 lines (82 loc) · 1.65 KB
/
11559.cpp
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
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
char map[12][6];
bool visited[12][6];
int mx[4] = { 1,0,-1,0 };
int my[4] = { 0,1,0,-1 };
vector<pair<int, int>> tmp, v1;
int boom = 0;
int temp = 0;
void dfs(int y,int x) {
for (int i = 0; i < 4; i++) {
int nx = x + mx[i];
int ny = y + my[i];
if (nx >= 0 && ny >= 0 && nx < 6 && ny < 12) {
if (map[ny][nx] != '.' && !visited[ny][nx] && map[ny][nx] == map[y][x]) {
temp++;
visited[ny][nx] = true;
tmp.push_back({ ny,nx });
dfs(ny, nx);
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for (int y = 0; y < 12; y++) {
for (int x = 0; x < 6; x++) {
cin >> map[y][x];
}
}
bool flag;
int ans = 0;
while (1) {
flag = false;
memset(visited, false, sizeof(visited));
v1.clear();
for (int y = 0; y < 12; y++) {
for (int x = 0; x < 6; x++) {
if (map[y][x] != '.' && !visited[y][x]) {
temp = 1;
tmp.push_back({ y,x });
visited[y][x] = true;
dfs(y, x);
if (temp >= 4) {
flag = true;
for (int i = 0; i < tmp.size(); i++) {
v1.push_back(tmp[i]);
}
}
tmp.clear();
}
}
}
for (int i = 0; i < v1.size(); i++) {
int x = v1[i].second;
int y = v1[i].first;
map[y][x] = '.';
}
for (int y = 10; y >= 0; y--) {
for (int x = 0; x < 6; x++) {
if (map[y][x] == '.') continue;
int tp = y;
while (1) {
if (tp == 11 || map[tp + 1][x] != '.') break;
map[tp + 1][x] = map[tp][x];
map[tp][x] = '.';
tp++;
}
}
}
if (flag) ans++;
else break;
}
cout << ans;
return 0;
}