# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
974357 | IUA_Hasin | Permutation (APIO22_perm) | C++17 | 12 ms | 1372 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>
#define endl "\n"
#define ll long long
using namespace std;
ll close_pow(ll n){
ll a = 1;
ll b = pow(2, a)-1;
ll ans = 1;
while(n>b){
// cout<<b<<endl;
ans++;
b = (ll)(pow(2, ans)-1);
if(b>n){
ans--;
break;
} else if(b==n){
break;
}
// cout<<b<<endl;
}
return ans;
}
std::vector<ll> dunno(ll n){
std::vector<ll> x;
while(n>0){
ll a = close_pow(n);
// cout<<a<<endl;
x.push_back(a);
ll b = (ll)(pow(2, a));
n = n-b+1;
}
return x;
}
std::vector<int> construct_permutation(long long k)
{
std::vector<ll> v = dunno(k-1);
ll sum = 0;
for(ll i=0; i<v.size(); i++){
sum = sum+v[i];
}
std::vector<int> ans;
ll ins = sum-1;
ll tempp = 0;
ll temp = v[tempp];
ll cnt = 0;
while(cnt<=sum-1){
for(ll i=1; i<=temp; i++){
ll a = ins-temp+i;
ans.push_back(a);
cnt++;
}
ins = ins-temp;
tempp++;
temp = v[tempp];
}
// for(int i=0; i<ans.size(); i++){
// cout << ans[i] << " ";
// }
// cout<<endl;
// ll exp = 0;
// for(int i=0; i<v.size(); i++){
// ll a = pow(2, v[i]);
// exp = exp+a-1;
// }
// cout<<exp+1<<endl;
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |