Cod sursa(job #2523604)

Utilizator flaviu_2001Craciun Ioan-Flaviu flaviu_2001 Data 14 ianuarie 2020 14:38:00
Problema Fractal Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>
#define ff first
#define ss second

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;

const string file = "fractal";
const ll INF = 9223372036854775807ll;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, inf = 2147483647;

int rec(int n, int x, int y)
{
    if (n == 0)
        return 0;
    int step = 1<<(n-1);
    if (x < step && y < step)
        return rec(n-1, y, x);
    if (x < step)
        return rec(n-1, x, y-step)+3*(step*step);
    if (y < step)
        return rec(n-1, x-step, y)+(step*step);
    return rec(n-1, step- (y-step), step-(x-step))+2*(step*step);
}

int main()
{
    ifstream fin (file+".in");
    ofstream fout (file+".out");
    int n, x, y;
    fin >> n >> x >> y;
    swap(x, y);
    --x, --y;
    fout << rec(n, x, y) << "\n";
    return 0;
}