백준/기타

[백준/C++] 1074번: Z

Koalitsiya 2023. 5. 22. 16:17

 

 

풀이

분할정복을 이용하는 문제이다.

#include <iostream>

using namespace std;

int n, row, column;
int answer = 0;

void ZFunc(int y, int x, int size) {
	if (y == row && x == column) {
		cout << answer;
		
		return;
	}

	if (row < y + size && row >= y && column < x + size && column >= x) {
		ZFunc(y, x, size / 2);
		ZFunc(y, x + size / 2, size / 2);
		ZFunc(y + size / 2, x, size / 2);
		ZFunc(y + size / 2, x + size / 2, size / 2);
	}
	else
		answer += size * size;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int size = 1;

	cin >> n >> row >> column;

	size <<= n;

	ZFunc(0, 0, size);

	return 0;
}