# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1114157 | PieArmy | Permutation (APIO22_perm) | C++17 | 1 ms | 336 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.
typedef long long ll;
ll pie(ll army){return (1ll<<army);}
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define endl '\n'
#define mid ((left+right)>>1)
const ll inf=2000000000000000005;
const int sonsuz=2000000005;
using namespace std;
ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;}
vector<int> construct_permutation(ll k){
vector<int>four;
while(k){
four.pb(k&3);
k>>=2;
}
reverse(four.begin(),four.end());
vector<int>res;
int cnt=0;
for(int i=0;i<four[0]-1;i++){
res.pb(-1);
cnt++;
}
for(int i=1;i<four.size();i++){
if(four[i]==0){
res.pb(1);
res.pb(1);
}
else if(four[i]==1){
res.pb(1);
res.pb(1);
res.pb(-1);
cnt++;
}
else if(four[i]==2){
res.pb(1);
res.pb(-1);
res.pb(1);
cnt++;
}
else if(cnt>=2){
res.pb(1);
res.pb(1);
res.pb(0);
}
else{
res.pb(1);
res.pb(-1);
res.pb(1);
res.pb(-1);
cnt+=2;
}
}
int las=0;
vector<int>ans(res.size());
for(int i=int(res.size())-1;i>=0;i--){
if(res[i]==-1){
ans[i]=las++;
}
}
las=int(res.size())-1;
for(int i=int(res.size())-1;i>=0;i--){
if(res[i]==1){
ans[i]=las--;
}
}
int mn=sonsuz;
for(int i=0;i<res.size();i++){
if(res[i]==0){
ans[i]=mn+2;
}
else mn=min(mn,ans[i]);
}
return ans;
}
/*
int main(){
ll n;cin>>n;
vector<int>ans=construct_permutation(n);
cout<<ans.size()<<endl;
for(int x:ans)cout<<x<<" ";
}*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |