# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
977303 | alex_2008 | Permutation (APIO22_perm) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
vector <int> construct(ll k) {
vector <int> ans;
int mx_num = 0;
int cnt = 1;
vector <int> path;
while (k > 1) {
if (k % 2 == 1) path.push_back(1), k--;
else path.push_back(2), k /= 2;
}
reverse(path.begin(), path.end());
for (auto it : path) {
if (it == 1) ans.insert(ans.begin(), mx_num++);
else ans.push_back(mx_num++);
}
return ans;
}
int main() {
vector <int> v = construct(43);
for (auto it : v) {
cout << it << " ";
}
}