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 <bits/stdc++.h>
using namespace std;
using ll = long long;
namespace {
vector<int> primes = {2, 3, 5};
deque<int> q;
int lim;
void mult(int x){
for (int i = lim + x - 2; i >= lim; i--){
q.push_back(i);
}
lim += x - 1;
}
void revert_mult(int x){
for (int i = 0; i < x - 1; i++) q.pop_back();
lim -= x - 1;
}
void add1(){
q.push_front(lim++);
}
void sub1(){
q.pop_front();
lim--;
}
bool solve(ll k){
if (k == 1) return true;
for (int i = 0; i < (int)primes.size(); i++){
if (k % primes[i] == 0){
bool success = solve(k / primes[i]);
if (!success) return false;
mult(primes[i]);
if (lim >= 90){
revert_mult(primes[i]);
return false;
}
return true;
}
}
bool success = solve(k - 1);
if (!success) return false;
add1();
if (lim >= 90){
sub1();
return false;
}
return true;
}
}
vector<int> construct_permutation(ll k){
lim = 0;
solve(k);
vector<int> v;
while (!q.empty()){
v.push_back(q.front());
q.pop_front();
}
return v;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |