Submission #983875

#TimeUsernameProblemLanguageResultExecution timeMemory
983875avighnaPermutation (APIO22_perm)C++17
91.33 / 100
3 ms504 KiB
#include <set>
#include <map>
#include <deque>

#include "perm.h"

typedef long long ll;

ll fsb(ll x) {
    for (ll i = 63; i >= 0; -- i) {
        if (x & (1LL << i)) {
            return i;
        }
    }
    return -1;
}

std::vector<int> construct_permutation(long long x) {
	std::deque<ll> ans;
    ll bit = fsb(x);
    for (ll i = 0; i < bit; ++ i) {
        ans.push_back(i);
    }
 
    for (ll i = bit - 1; i >= 0; -- i) {
        if (x & (1LL << i)) {
            ans.push_front(bit - i - 1);
        }
    }

	for (auto &i : ans) {
		i *= 1000;
	}
	std::set<ll> st;
	for (ll i = ans.size() - 1; i >= 0; -- i) {
		while (st.count(ans[i])) {
			ans[i]++;
		}
		st.insert(ans[i]);
	}

	std::map<ll, ll> mp;
	auto it = st.begin();
	for (ll j = 0; j < ans.size(); ++ j) {
		mp[*it] = j;
		it++;
	}

	std::vector<int> ret;
	for (auto &i : ans) {
		ret.push_back(mp[i]);
	}
	return ret;
}

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:44:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for (ll j = 0; j < ans.size(); ++ j) {
      |                 ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...