흔한 분할정복 문제며, 쿼드트리를 사용하는 문제였다.
자주 보이던 문제 유형이라 어렵진 않았다. 시키는대로 구현하면 된다.
#include <string>
#include <vector>
using namespace std;
vector<int> ans(2, 0);
vector<vector<int>> map;
void QUARD(int start_x, int start_y, int n)
{
int find_num = map[start_x][start_y];
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if (map[start_x + i][start_y + j] != find_num)
{
n /= 2;
QUARD(start_x, start_y, n);
QUARD(start_x + n, start_y, n);
QUARD(start_x, start_y + n, n);
QUARD(start_x + n, start_y + n, n);
return;
}
ans[find_num]++;
return;
}
vector<int> solution(vector<vector<int>> arr) {
vector<int> answer;
int n = arr.size();
map = arr;
QUARD(0, 0, n);
answer = ans;
return answer;
}
'Coding_Test 연습 > Programmers' 카테고리의 다른 글
[프로그래머스] (C++) LV2 숫자 블록 (0) | 2022.06.10 |
---|---|
[프로그래머스] (C++) LV2 멀리 뛰기 (0) | 2022.06.09 |
[프로그래머스] (C++) LV2 n^2 배열 자르기 (0) | 2022.06.05 |
[프로그래머스] (C++) LV2 3 x n 타일링 (0) | 2022.06.04 |
[프로그래머스] (C++) LV2 점프와 순간 이동 (0) | 2022.06.04 |