Cod sursa(job #2750362)

Utilizator NashikAndrei Feodorov Nashik Data 10 mai 2021 22:24:20
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
//#include <iostream>
#include <fstream>
using namespace std;
ifstream cin("fractal.in");
ofstream cout("fractal.out");
int prod[20];
int solve(int k,int x,int y){
    if(k==0){
        return 0;
    }
    int pr=prod[k-1];
    if(x<=pr and y<=pr){
        int a=solve(k-1,y,x);
        return a;
    }
    if(x>pr and y<=pr){
        int a=solve(k-1,x-pr,y)+pr*pr;
        return a;
    }
    if(x>pr and y>pr){
        int a=solve(k-1,x-pr,y-pr)+pr*pr*2;
        return a;
    }
    if(x<=pr and y>pr){
        int a=solve(k-1,2*pr-y+1,pr-x+1)+pr*pr*3;
        return a;
    }
}
int main()
{
    int k,x,y;
    prod[0]=1;
    for(int i=1;i<=15;i++){
        prod[i]=prod[i-1]*2;
    }
    cin>>k>>x>>y;
    swap(x,y);
    cout<<solve(k,x,y);
    return 0;
}