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>
#include "perm.h"
#define pb push_back
using namespace std;
vector<int> construct_permutation(long long k){
vector<int> ans;
for(long long N = k; N <= k + 500; ++N){
if(N % 2 != 0)
continue;
multiset<int> tmp;
vector<int> v;
for(int i = 1; (1LL << i) <= N; ++i){
if(N & (1LL << i))
tmp.insert(i);
}
if((int)tmp.size() > N - k + 1)
continue;
bool ok = true;
while((int)tmp.size() < N - k + 1){
auto it = tmp.lower_bound(2);
if(it == tmp.end()){
ok = false;
break;
}
tmp.erase(it);
int add = *it - 1;
tmp.insert(add);
tmp.insert(add);
}
if(!ok)
continue;
int m = 0;
for(auto i : tmp)
m += i;
for(auto i : tmp){
vector<int> tttt;
for(int j = 1; j <= i; ++j)
tttt.pb(--m);
reverse(tttt.begin(), tttt.end());
for(auto j : tttt)
v.pb(j);
}
if(ans.empty() || (int)ans.size() > (int)v.size())
ans = v;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |