# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1202078 | raul2008487 | Permutation (APIO22_perm) | C++20 | 2 ms | 328 KiB |
#include<bits/stdc++.h>
#include "perm.h"'
#define ll int
#define pb push_back
#define in insert
#define fi first
#define se second
#define vl vector<ll>
#define all(v) v.begin(), v.end()
#define endl '\n'
using namespace std;
void add(vl &a, ll pos, ll x){
vl res;
for(int i = 0; i < pos; i++){
res.pb(a[i]);
}
res.pb(x);
for(int i = pos; i < a.size(); i ++){
res.pb(a[i]);
}
a = res;
}
vector<int> construct_permutation(long long k)
{
ll l = __lg(k);
vl ans;
k -= (1ll << l);
for(int i = 0; i < l; i++){
ans.pb(i);
}
for(int i = l - 1; i >= 0; i--){
if((k >> i) & 1){
add(ans, i, l++);
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |