코딩테스트/백준

[실1] 1074 - Z

ShovelingLife 2022. 12. 7. 23:18
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>

#pragma warning(disable : 4996)

using namespace std;

int n, r, c, ans = 0;

void dc(int x, int y, int size)
{
    if (c == x &&
        r == y)
    {
        cout << ans;
        return;
    }
    else if (c < x + size &&
             r < y + size &&
             c >= x &&
             r >= y)
    {
        auto half = size / 2;
        dc(x, y, half);
        dc(x + half, y, half);
        dc(x, y + half, half);
        dc(x + half, y + half, half);
    }
    else
        ans += pow(size, 2);
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> r >> c;
    dc(0, 0, pow(2, n));
    return 0;
}