# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
785322 | mindiyak | Permutation (APIO22_perm) | C++17 | 1 ms | 212 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 <cmath>
#include <deque>
#include <iostream>
#define ll long long
#define pb push_back
using namespace std;
int binary_search(ll val){
int l = 0,r = 61;
while(l<r){
int mid = (l+r) >> 1;
// cout << val << " " << l << " " << mid << " " << r << endl;
if(val < pow(2,mid)){
r = mid-1;
}else{
l = mid+1;
}
}
// cout << "lenght " << l << endl << endl;
return l;
}
std::vector<int> construct_permutation(long long k)
{
deque<pair<int,int>> ans;
int n = 0;
while(k > 0){
int temp = binary_search(k)-1;
ans.push_front({n,n+temp});
k -= pow(2,temp+1);
n += temp + 1;
}
vector<int> arr;
for(int i=0;i<ans.size();i++){
// cout << ans[i].first << " " << ans[i].second << endl;
for(int j=ans[i].first;j<=ans[i].second;j++){
arr.pb(j);
}
}
// for(int i=0;i<arr.size();i++){
// cout << arr[i] << " ";
// } cout << endl;
return arr;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |