-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11559.cpp
More file actions
98 lines (90 loc) · 2.16 KB
/
11559.cpp
File metadata and controls
98 lines (90 loc) · 2.16 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
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
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string.h>
using namespace std;
char arr[12][6];
int dy[4]={1,-1,0,0};
int dx[4]={0,0,1,-1};
int visited[12][6];
int answer=-1;
int flag;
void bfs(int i, int j){
visited[i][j]=1;
queue<pair<int, int> > q;
vector<pair<int, int> > v;
char color = arr[i][j];
q.push(make_pair(i,j));
v.push_back(make_pair(i, j));
while(!q.empty()){
int y = q.front().first;
int x = q.front().second;
q.pop();
for(int d=0; d<4; d++){
int ny = y + dy[d];
int nx = x + dx[d];
if(ny<0 || ny>=12 || nx<0 || nx>=6) continue;
if(visited[ny][nx]) continue;
if(arr[ny][nx]!=color) continue;
visited[ny][nx]=1;
q.push(make_pair(ny, nx));
v.push_back(make_pair(ny, nx));
}
}
if(v.size()>=4){
flag=1;
for(int i=0; i<v.size(); i++){
arr[v[i].first][v[i].second]='.';
}
}
}
bool boom(){
memset(visited, 0, sizeof(visited));
answer++;
flag=0;
for(int i=0; i<12; i++){
for(int j=0; j<6; j++){
if(visited[i][j]==0 && arr[i][j]!='.'){
bfs(i, j);
}
}
}
for(int j=0; j<6; j++){
for(int i=10; i>=0; i--){
for(int k=11; k>i; k--){
if(arr[k][j]=='.'){
arr[k][j]=arr[i][j];
arr[i][j]='.';
break;
}
}
}
}
// for(int j=0; j<6; j++){
// vector<char> temp;
// for(int i=11; i>=0; i--){
// if(arr[i][j]!='.'){
// temp.push_back(arr[i][j]);
// }
// }
// for(int i=0; i<temp.size(); i++){
// arr[11-i][j]=temp[i];
// }
// for(int i=temp.size(); i<12; i++){
// arr[11-i][j]='.';
// }
// }
return flag;
}
int main(){
for(int i=0; i<12; i++){
for(int j=0; j<6; j++){
char c; cin>>c;
arr[i][j]=c;
}
}
while(boom()){};
cout<<answer<<endl;
return 0;
}