# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
623528 | Lobo | Permutation (APIO22_perm) | C++17 | 2 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<iostream>
#include<vector>
#include<deque>
#include<math.h>
using namespace std;
#define pb push_back
#define pf push_front
#define int long long
vector<int32_t> construct_permutation(int k)
{
vector<int32_t> seq;
int lg = 0;
for(int i = 0; i <= 60; i++) {
if(k >= (1LL<<i)) lg = i;
}
if(lg < 2) {
for(int i = k-2; i >= 0; i--) {
seq.pb(i);
}
return seq;
}
deque<int> ans;
int cur = 0;
//do the first 2/3 separate
if((1LL<<(lg-1))&k) {
//begins with 11
ans.pb(cur++); //10
ans.pf(cur++); //11
//ans = 10
cur = ans.size();
lg-=2;
}
else if((1LL<<(lg-2))&k){
//begins with 100
ans.pb(cur++); //10
ans.pf(cur++); //11
ans.pf(cur++); //100
ans.pf(cur++); //101
//ans = 3210
cur = ans.size();
lg-=3;
}
else {
//begins with 101
ans.pb(cur++); //10
ans.pf(cur++); //11
ans.pf(cur++); //100
//ans = 210
cur = ans.size();
lg-=3;
}
//do the rest in groups of 2
while(lg != -1) {
if(lg == 0 || ((1LL<<lg)&k) == 0) {
//if it is the last or 0
ans.pb(cur++); //_0
if((1LL<<lg)&k) ans.pf(cur++); //_1
lg--;
}
else if((1LL<<(lg-1))&k) {
//it is 11 -> sum 3
ans.pb(cur++); //_0
ans.pb(cur++); //_00
for(int i = 0; i < ans.size(); i++) {
if(ans[i] > 1) ans[i]++;
}
ans.pb(2); //_11
cur++;
lg-=2;
}
else {
//it is 10
ans.pb(cur++); //_0
ans.pf(cur++); //_1
ans.pb(cur++); //_10
lg-=2;
}
}
for(auto x : ans) {
seq.pb(x);
}
return seq;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |