-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLv5_프렌즈4블록.cpp
47 lines (42 loc) · 966 Bytes
/
Lv5_프렌즈4블록.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
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int solution(int m, int n, vector<string> board) {
int answer = 0;
bool flag = false;
while (1) {
vector<vector<bool>> check(m, vector<bool>(n, false));
flag = false;
// 4개 블록 검사
for (int i = 0; i < m - 1; ++i) {
for (int j = 0; j < n - 1; ++j) {
char c = board[i][j];
if (c == '*') // 빈공간
continue;
if (board[i][j + 1] == c && board[i + 1][j] == c && board[i + 1][j + 1] == c) {
check[i][j] = true;
check[i][j + 1] = true;
check[i + 1][j] = true;
check[i + 1][j + 1] = true;
flag = true;
}
}
}
if (!flag)
break;
// 블럭 아래로 내리기
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (check[i][j]) {
for (int k = i - 1; k >= 0; k--) {
board[k + 1][j] = board[k][j];
board[k][j] = '*';
}
++answer;
}
}
}
}
return answer;
}