# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
574680 | WongChun1234 | Permutation (APIO22_perm) | C++17 | 1 ms | 212 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;
typedef long long ll;
int pos[100];
vector<int> ret,pres;
void add(int newpos){
for (auto &i:ret) if (i>=newpos) i++;
ret.push_back(newpos);
memset(pos,-1,sizeof(pos));
for (int i=0;i<ret.size();i++) pos[ret[i]]=i;
}
vector<int> construct_permutation(ll k){
memset(pos,-1,sizeof(pos));
ret.clear(); pres.clear();
while (k){
pres.push_back(k%4);
k/=4;
}
reverse(pres.begin(),pres.end());
if (pres[0]==1){
}else if (pres[0]==2){
add(0);
}else if (pres[0]==3){
add(0);
add(0);
}
for (int i=1;i<pres.size();i++){
if (pres[i]==0){
add(ret.size());
add(ret.size());
}else if (pres[i]==1){
add(ret.size());
add(ret.size());
add(0);
}else if (pres[i]==2){
add(ret.size());
add(0);
add(ret.size());
}else if ((pos[0]==-1)||(pos[1]==-1)||(pos[1]>pos[0])){
add(ret.size());
add(0);
add(ret.size());
add(0);
}else{
add(ret.size());
add(2);
add(ret.size());
}
}
return ret;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |