Submission #916502

#TimeUsernameProblemLanguageResultExecution timeMemory
916502wiiPermutation (APIO22_perm)C++17
91.33 / 100
2 ms684 KiB
#include <bits/stdc++.h>
#include <perm.h>

using namespace std;

void dnc(deque<int> &v, int id, long long u) {
    if (id < 0) return;

    if (u & 1) {
        dnc(v, id - 1, u >> 1);
        v.push_back(id);
    } else {
        dnc(v, id - 1, u - 1);
        v.push_front(id);
    }
}

vector<int> construct_permutation(long long k) {
    k -= 1;

    int cnt = 0;
    for (long long x = k; x > 0; x = (~x & 1 ? --x : x >> 1), ++cnt);

    deque<int> ans;
    dnc(ans, cnt - 1, k);

    return vector<int>(ans.begin(), ans.end());
}

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:22:36: warning: operation on 'x' may be undefined [-Wsequence-point]
   22 |     for (long long x = k; x > 0; x = (~x & 1 ? --x : x >> 1), ++cnt);
      |                                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~
perm.cpp:22:36: warning: operation on 'x' may be undefined [-Wsequence-point]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...