Cod sursa(job #3325193)

Utilizator postolacheepostolache postolachee Data 24 noiembrie 2025 22:15:22
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;

void sigma(int n, int &x, int &y, int rx, int ry){
    if(ry == 0){
        if(rx == 1){
            x = n - 1 - x;
            y = n - 1 - y;
        }
        swap(x, y);
    }
}

int xy2d(int n, int x, int y){
    int d = 0;
    for(int s = n / 2;s > 0;s /= 2){
        int rx = (x & s) ? 1 : 0;
        int ry = (y & s) ? 1 : 0;
        d += s * s * ((3 * rx) ^ ry);
        sigma(s * 2, x, y, rx, ry);
    }
    return d;
}

signed main(){
    ifstream cin ("fractal.in");
    ofstream cout ("fractal.out");

    int k, x, y;cin >> k >> x >> y;
    int n = 1LL << k;
    cout << xy2d(n, x - 1, y - 1) << "\n";
    return 0;
}