Cod sursa(job #2326482)

Utilizator gabiluciuLuciu Gabriel gabiluciu Data 23 ianuarie 2019 16:35:35
Problema Fractal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.4 kb
#include <cstdio>
#include <algorithm>
#include <time.h>
#include <queue>
#include <cmath>
#include <stack>
#include <fstream>
//#include <iostream>
#include <bitset>

using namespace std;
#define nl '\n'
#define all(v) v.begin(),v.end()
#define eb(x) emplace_back(x)
#define ull unsigned long long
#define N 1002
ifstream cin("fractal.in");
ofstream cout("fractal.out");

template<class a, class type>
void print(a v, type t) {
    for_each(all(v), [](type x) { cout << x << ' '; });
    cout << nl;
}

double logXBaseY(double X, double Y) {
    return log2(X) / log2(Y);
}

int ord, lin, col;
vector<ull> power4(16);

ull solve(int ordin, int x, int y) {
    if (!ordin)
        return 0;

    int mij = (1 << (ordin - 1));

    if (x <= mij && y <= mij) {
        return solve(ordin - 1, y, x);
    } else if (x <= mij && y > mij) {
        return mij * mij + solve(ordin - 1, x, y - mij);
    } else if (y > mij && x > mij) {
        return 2 * mij * mij + solve(ordin - 1, x - mij, y - mij);
    } else if (x > mij && y <= mij)
        return 3 * mij * mij + solve(ordin - 1, mij-y+1, mij*2-x+1);
}

int main() {
    ios_base::sync_with_stdio(false);
    clock_t tStart = clock();
    cin >> ord >> col >> lin;
    power4[0] = 1;
    for (int i = 1; i < 16; ++i) {
        power4[i] = power4[i - 1] * 4;
    }
    cout << solve(ord, col, lin);
    printf("\nTime taken: %.2fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
}