제출 #642037

#제출 시각아이디문제언어결과실행 시간메모리
642037Alexandruabcde순열 (APIO22_perm)C++17
91.33 / 100
2 ms340 KiB
#include "perm.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int ComputePower (LL k) {
    int l = 0;

    while ((1LL<<l) <= k / 2)
        ++ l;

    return l;
}

std::vector<int> construct_permutation(long long k)
{
    int L = ComputePower(k);

    k -= ((1LL<<L));

    vector <int> ans;
    vector <int> V;

    int value = -1;

    for (int i = 0; i < L; ++ i ) {
        ++ value;

        if ((k&(1LL<<i))) {
            V.push_back(value);
            ++ value;
        }

        ans.push_back(value);
    }

    for (int i = V.size()-1; i >= 0; -- i )
        ans.push_back(V[i]);

    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...