https://school.programmers.co.kr/learn/courses/30/lessons/68936
#include <string>
#include <vector>
using namespace std;
typedef struct _POS
{
size_t x;
size_t y;
} POS;
class QurdTree
{
public:
QurdTree(POS pos, size_t cnt)
: _pos(pos), _cnt(cnt)
{
}
void operator()(const vector<vector<int>>& arr, vector<int>& answer, const QurdTree& root)
{
const auto pivot = arr[root.GetPos().x][root.GetPos().y];
const int itv = root.GetCnt() / 2;
for (size_t i = 0; i < _cnt; ++i)
{
for (size_t j = 0; j < _cnt; ++j)
{
if (pivot != arr[i + _pos.x][j + _pos.y])
{
QurdTree qt1(POS{ root.GetPos().x, root.GetPos().y }, itv);
qt1(arr, answer, qt1);
QurdTree qt2(POS{ root.GetPos().x + itv, root.GetPos().y }, itv);
qt2(arr, answer, qt2);
QurdTree qt3(POS{ root.GetPos().x, root.GetPos().y + itv }, itv);
qt3(arr, answer, qt3);
QurdTree qt4(POS{ root.GetPos().x + itv, root.GetPos().y + itv }, itv);
qt4(arr, answer, qt4);
return;
}
}
}
++answer[pivot];
}
const POS GetPos() const { return _pos; }
const size_t GetCnt() const { return _cnt; }
private:
POS _pos;
size_t _cnt;
};
vector<int> solution(vector<vector<int>> arr) {
vector<int> answer = { 0, 0 };
QurdTree qt(POS{ 0, 0 }, arr.size());
qt(arr, answer, qt);
return answer;
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (탐욕법(Greedy)) Lv 2. 큰 수 만들기 (0) | 2023.07.27 |
---|---|
[Programmers] Lv 2. 택배상자 (0) | 2023.07.26 |
[Programmers] (완전탐색) Lv 2. 소수 찾기 (0) | 2023.07.24 |
[Programmers] (정렬) Lv 2. 가장 큰 수 (0) | 2023.07.24 |
[Programmers] (스택/큐) Lv 2. 다리를 지나는 트럭 (0) | 2023.07.23 |
댓글