#include "perm.h"
#include <bits/stdc++.h>
using namespace std;
set<long long> p;
vector<int> construct_permutation(long long k)
{
int q = 1;
if (p.empty()){
while (true){
p.insert(pow(2, q));
if (q == 62){
break;
}
q++;
}
}
long long remaining = k;
if (k % 2 != 0){
remaining -= 1;
}
vector<int> out;
vector<long long> found;
int os = 0;
if (k % 2 != 0){
out.push_back(INT_MAX);
os++;
}
int fs = 0;
while (remaining > 0){
long long t = *(--p.upper_bound(remaining));
fs++;
remaining -= t;
found.push_back(t);
}
for (int i = 0; i < log2(found[0]); ++i){
out.push_back(i * 2);
os++;
}
for (int i = 1; i < fs; ++i){
out.push_back((log2(found[i]) - 1) * 2 + 1);
os++;
}
vector<int> outsorted = out;
sort(outsorted.begin(), outsorted.end());
for (int i = 0; i < os; ++i){
for (int j = 0; j < os; ++j){
if (outsorted[i] == out[j]){
out[j] = i;
break;
}
}
}
return out;
}
/*
long long validator(vector<long long>& dpcache, vector<int>& k, int i){
if (dpcache[i] != -1){
return dpcache[i];
}
long long count = 1;
for (int j = i + 1; j < k.size(); ++j){
if (k[j] > k[i]){
count += validator(dpcache, k, j);
}
}
return dpcache[i] = count;
}
int main(){
long long n;
cin >> n;
auto g = construct_permutation(n);
for (auto h : g){
cout << h << endl;
}
long long count = 1;
vector<long long> dpcache(g.size() + 10, -1);
for (int i = 0; i < g.size(); ++i){
count += validator(dpcache, g, i);
}
cout << endl << count << endl << g.size();
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Partially correct |
2 ms |
300 KB |
Partially correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
300 KB |
Output is correct |
8 |
Partially correct |
2 ms |
340 KB |
Partially correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Partially correct |
2 ms |
340 KB |
Partially correct |
11 |
Partially correct |
2 ms |
340 KB |
Partially correct |
12 |
Partially correct |
2 ms |
340 KB |
Partially correct |
13 |
Partially correct |
2 ms |
296 KB |
Partially correct |