Cod sursa(job #2590143)

Utilizator alex_benescuAlex Ben alex_benescu Data 27 martie 2020 16:10:33
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("fractal.in");
ofstream out("fractal.out");
int k,x,y;
long long pw[123];
int solve(int k,int x,int y){
if(k==0)
return 0;
int len=pw[k-1];
if(x<=len&&y<=len)
return solve(k-1,y,x);
if(x>len&&y<=len)
return len*len+solve(k-1,x-len,y);
if(x>len&&y>len)
return 2*len*len+solve(k-1,x-len,y-len);
return 3*len*len+solve(k-1,2*len-y+1,len-x+1);
}
int main(){
pw[0]=1;
for(int i=1; i<=30; i++)
pw[i]=2*pw[i-1];
in>>k>>y>>x;
out<<solve(k,x,y);
return 0;
}