# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1060949 | KasymK | 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 "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
vector<int> construct_permutation(ll k){
if(k <= 90){
vector<int> A;
for(int i = k-2; i >= 0; --i)
A.pb(i);
return A;
}
vector<int> A;
int sm = 0, sm_ = 0;
bool ok = false;
vector<int> answer;
for(int i = 60; i >= 0; --i){
if(ok){
A.pb(sm);
sm++;
if(k>>i&1){
sm_--;
A.pb(sm_);
}
}
if(k>>i&1)
ok = true;
}
for(auto &i : A)
answer.pb(i-sm_);
return answer;
}
int main(){
vector<int> kk = construct_permutation(14);
for(int i : kk)
printf("%d ", i);
puts("");
return 0;
}