Submission #1343834

#TimeUsernameProblemLanguageResultExecution timeMemory
1343834ElyesChaabouniPermutation (APIO22_perm)C++20
91.33 / 100
1 ms360 KiB
#include "perm.h"
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second

vector<int> construct_permutation(long long k) {
    ll m = 1;
    while ((1ll<<m) <= k) m++;
    m--;

    ll n = m;
    for (ll i = 0; i < m; ++i) {
        if (k & (1ll << i))
            n++;
    }

//    string s = "";
//    for (ll i = 0; i < m; ++i) {
//        s += to_string(1 << i);
//    }
    vector<int>ans;
    int ptr=n-1;

    for (ll i = 0; i < m; ++i) {
        if (k & (1ll << i)){
            ans.pb(ptr);
            ptr--;
        }

        ans.pb(i);
    }

//    cout << n << ' ' << m << endl;
//    for (ll i = 0; i < n; ++i) {
//        cout << ans[i] << ' ';
//    }
//    cout << endl;

    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...