# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
652952 | aryan12 | Permutation (APIO22_perm) | C++17 | 4 ms | 340 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 "perm.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> construct_permutation(long long k)
{
k--;
long long cnt = 0;
while(true)
{
if((1LL << (cnt + 1)) - 1 <= k)
{
cnt++;
}
else
{
break;
}
}
k -= (1LL << cnt) - 1;
// cout << "cnt = " << cnt << endl;
vector<int> ans;
int omk = 1;
for(int i = 0; i < cnt; i++)
{
ans.push_back(omk);
omk += 3;
}
omk -= 4;
// cout << "k = " << k << endl;
for(long long i = cnt - 1; i >= 0; i--)
{
if((1LL << i) <= k)
{
k -= (1LL << i);
// cout << "i = " << i << endl;
ans.push_back(omk);
if((1LL << i) <= k)
{
k -= (1LL << i);
// cout << "i = " << i << endl;
ans.push_back(omk - 1);
}
}
// cout << "k = " << fixed << setprecision(0) << k << endl;
omk -= 3;
}
map<int, int> cc;
for(int i = 0; i < ans.size(); i++)
{
cc[ans[i]]++;
}
int ccc = 0;
for(auto i: cc)
{
cc[i.first] = ccc++;
}
for(int i = 0; i < ans.size(); i++)
{
ans[i] = cc[ans[i]];
// cout << ans[i] << " ";
}
// cout << "k = " << k << endl;
// cout << "perm\n";
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |