Submission #601281

#TimeUsernameProblemLanguageResultExecution timeMemory
601281dooweyPermutation (APIO22_perm)C++17
82.05 / 100
9 ms724 KiB
#include "perm.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair


vector<int> construct_permutation(ll k)
{

	if(k == 1) return {};
    if(k % 2 == 1){
        ll p = 1;
        int leng = 0;
        while(2ll * p <= k){
            p *= 2ll;
            leng ++ ;
        }
        if(p == k){
            vector<int> z;
            for(int i = 0 ; i < leng; i ++ ){
                z.push_back(leng);
            }
            return z;
        }
        else{
            p -- ;
            k -= p;
            vector<int> sol = construct_permutation(k);
            vector<int> res;
            for(int i = 0 ; i < leng; i ++ ){
                res.push_back(sol.size() + i);
            }
            for(auto x : sol) res.push_back(x);
            return res;
        }
    }
    else{
        vector<int> sol = construct_permutation(k / 2ll);
        sol.push_back(sol.size());
        return sol;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...