Submission #1225279

#TimeUsernameProblemLanguageResultExecution timeMemory
1225279SpyrosAlivPermutation (APIO22_perm)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int LOG = 10;

vector<int> construct_permutation(ll k) {
    k--;
    vector<int> perm;
    vector<int> bits;
    ll curr = 0;
    for (int i = 0; i < LOG; i++) {
        curr |= (1LL << i);
        if (k >= curr) {
            bits.push_back(i);
        }
        else break;
    }
    curr /= 2;
    k -= curr;
    vector<int> after;
    for (int i = 0; i < LOG; i++) {
        if (!((k >> i) & 1)) continue;
        after.push_back(i);
        for (int j = 0; j < (int)bits.size(); j++) {
            if (bits[j] >= i) bits[j]++;
        }
    }
    reverse(after.begin(), after.end());
    for (auto x: bits) perm.push_back(x);
    for (auto x: after) perm.push_back(x);
    return perm;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...