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>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include "perm.h"
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
using namespace std;
vector<int> perm(ll k, ll shi){
if (k==2){
return {(int)shi};
}
ll imp = k;
vector<ll> ops;
deque<ll> sus;
while (k>1){
bool flag = false;
FOR(i,2,min((ll)10, (ll)k)){
if (k%i==0){
ops.push_back(i);
k /= i;
flag = true;
break;
}
}
if (flag) continue;
ops.push_back(1);
k -= 1;
}
ll cur = shi;
reverse(ops.begin(), ops.end());
for (auto&i : ops){
if (i==1) sus.push_front(cur++);
else{
ll temp = 0;
for (auto&j : perm(i, cur)){
temp++;
sus.push_back(j);
}
cur += temp;
}
}
vector<int> ans;
for (auto&i : sus) ans.push_back(i);
return ans;
}
vector<int> construct_permutation(long long k){
return perm(k, 0);
}
Compilation message (stderr)
perm.cpp: In function 'std::vector<int> perm(ll, ll)':
perm.cpp:19:5: warning: unused variable 'imp' [-Wunused-variable]
19 | ll imp = k;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |