Cod sursa(job #3358065)

Utilizator EuMirea21Mirea Costin-Alexandru EuMirea21 Data 14 iunie 2026 14:05:26
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ifstream fin("fractal.in");
ofstream fout("fractal.out");
int n,x,y;
int ans(int lat)
{
    int mij = lat/2;
    if(lat == 1) return 0;
    if(x <= mij && y <= mij)
    {
        swap(x,y);
        return ans(lat/2);
    }
    else if(x > mij && y <= mij)
    {
        x-=mij; // in rest nu se schimba
        return (lat/2)*(lat/2) + ans(lat/2);
    }
    else if(x > mij && y > mij)
    {
        y-=mij;
        x-=mij;
        return 2 * (lat/2)*(lat/2) + ans(lat/2);
    }
    else
    {
        y = lat - y + 1;
        x = mij - x + 1;
        swap(x,y);
        return 3 * (lat/2)*(lat/2) + ans(lat/2);
    }
}
int main()
{
    // recursiv se poate face ca pozitia in care sfert se afla nr recursiv
    // ok deci nu putem face cu stocare clar
    fin >> n >> y >> x;
    fout << ans((1 << n));
    fin.close();
    fout.close();
    return 0;
}