# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
573159 | Vanilla | Permutation (APIO22_perm) | C++17 | 3 ms | 340 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>
using namespace std;
long long find (long long k) {
for (long long i = 1; i < 63; i++){
if ((1ll << i) > k) return i-1;
}
}
std::vector<int> construct_permutation(long long k)
{
vector <int> rs;
long long pw [100] = {};
k-=2;
int sp = 1000;
pw[0] = sp - 1;
rs.push_back(sp);
int step = 1;
while (k != 0) {
int hg = min(int(find(k)), step);
if (pw[hg] == 0) {
pw[hg] = pw[hg - 1] + sp;
}
rs.push_back(pw[hg]--);
k-=(1ll << hg);
step++;
}
vector <int> v = rs;
sort(v.begin(), v.end());
map <int, int> mp;
for (int i = 0; i < v.size(); i++){
mp[v[i]] = i;
}
for (int &i: rs){
i = mp[i];
}
return rs;
}
// int main (){
// construct_permutation(12);
// }
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |