Submission #594729

#TimeUsernameProblemLanguageResultExecution timeMemory
594729OzyPermutation (APIO22_perm)C++17
91.33 / 100
2 ms340 KiB
#include "perm.h"
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define pb push_back
#define pf push_front

lli cont;
deque<lli> perm;

void arma(lli num) {
    lli mitad = num/2;

    if (mitad == 0) return;

    arma(mitad);
    perm.pb(cont++);
    if (num&1) perm.pf(cont++);
}

std::vector<int> construct_permutation(long long k)
{

    cont = 0;
    arma(k);

    lli act;
    vector<int> res;
    res.resize(cont);
    cont = 0;
    while (!perm.empty()) {
        act = perm.front();
        perm.pop_front();
        res[cont++] = act;
    }
    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...