Submission #973886

#TimeUsernameProblemLanguageResultExecution timeMemory
973886PanndaPermutation (APIO22_perm)C++17
100 / 100
2 ms668 KiB
#include "perm.h"

#include <bits/stdc++.h>
using namespace std;

vector<int> construct_permutation(long long k) {
    int b = 63 - __builtin_clzll(k);
    k -= 1LL << b;
    vector<int> key(b);
    iota(key.begin(), key.end(), 0);
    int cnt = 0;
    while (k > 0) {
        b = 63 - __builtin_clzll(k);
        if (cnt >= 1 && b > 0 && ((k >> (b - 1)) & 1)) {
            b--;
            for (int &v : key) {
                if (v >= b) v++;
            }
            key.insert(key.end() - 2, b);
            k -= 3LL << b;
        } else {
            for (int &v : key) {
                if (v >= b) v++;
            }
            key.push_back(b);
            k -= 1LL << b;
            cnt++;
        }
    }
    return key;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...