https://programmers.co.kr/learn/courses/30/lessons/42894
#include <string>
#include <vector>
using namespace std;
int answer = 0;
int R, C;
vector<vector<int>> b;
bool flag;
bool CanDrop(int ii, int jj) {
for (int i = 0; i < ii; i++) {
if (b[i][jj] != 0) return false;
}
return true;
}
void FindBlock(int ii, int jj, int r, int c) {
int count = 0;
int block = -1;
for (int i = ii; i < ii + r; i++) {
for (int j = jj; j < jj + c; j++) {
if (!(i >= 0 && i < R && j >= 0 && j < C)) return;
if (b[i][j] == 0) {
count++;
if (CanDrop(i, j) == false) return;
}
else {
if (block == -1) block = b[i][j];
else {
if (block != b[i][j]) return;
}
}
if (count > 2) return;
}
}
answer++;
for (int i = ii; i < ii + r; i++) {
for (int j = jj; j < jj + c; j++) {
b[i][j] = 0;
}
}
flag = true;
}
int solution(vector<vector<int>> board) {
R = board.size();
C = board[0].size();
b = board;
flag = true;
while (flag) {
flag = false;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
FindBlock(i, j, 2, 3);
FindBlock(i, j, 3, 2);
}
}
}
return answer;
}