Cod sursa(job #2737617)

Utilizator PinkiePie1189Preoteasa Mircea-Costin PinkiePie1189 Data 4 aprilie 2021 22:00:17
Problema Fractal Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <fstream>
#include <algorithm>
#include <climits>
#include <iostream>


long long divide (int k, int x, int y) {
    if (k == 1) {
        if (x == 1 && y == 1) {
            return 0;
        }

        if (x == 2 && y == 1) {
            return 3;
        }

        if (x == 1 && y == 2) {
            return 1;
        }

        return 2;
    }


    long long bound = (1 << (k - 1));

    if (x <= bound && y <= bound) {
        return divide(k - 1, y, x);
    }

    if (x <= bound && y > bound) {
        return (2LL * bound) + divide(k - 1, x, y - bound);
    }

    if (x > bound && y > bound) {
        return (4LL * bound) + divide(k - 1, x - bound, y - bound);
    }
    return (6LL * bound) + divide(k - 1, 2 * bound - 1 - y, 2 * bound - 1 - (x - bound));
}
int main() {
    std::ifstream fin("fractal.in");
    std::ofstream fout("fractal.out");
    int k, x, y;
    fin >> k >> x >> y;
    fout << divide(k, x, y);
    return 0;
}