Submission #926892

#TimeUsernameProblemLanguageResultExecution timeMemory
926892irmuunSwap (BOI16_swap)C++17
21 / 100
1066 ms604 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin>>n; vector<ll>a(n+1); a[0]=0; for(ll i=1;i<=n;i++){ cin>>a[i]; } vector<ll>ans(n+1,1e18); for(ll j=0;j<(1<<(n/2));j++){ ll cur=j; vector<ll>b=a; for(ll i=1;i<=n;i++){ ll x=i*2,y=i*2+1; if(x>n) continue; if(x==n){ if(b[i]>b[x]) swap(b[i],b[x]); } else{ ll c[3]; c[0]=b[i]; c[1]=b[x]; c[2]=b[y]; sort(c,c+3); if(b[i]==c[0]) continue; if(b[x]==c[0]){ swap(b[x],b[i]); } else{ if(cur&1){ swap(b[i],b[x]); } swap(b[i],b[y]); cur=cur>>1; } } } ans=min(ans,b); } for(ll i=1;i<=n;i++){ cout<<ans[i]<<' '; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...