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;
int r,n,yo;
vector<int>habilidades;
vector<pair<int,int>>campo;
vector<int>posciciones;
void ronda(){
for(int i=0;i<n;i++){
if(campo[i].first>campo[i].second){
swap(campo[i].first,campo[i].second);
}
}
int aux=campo[0].second;
campo[0].second=campo[1].first;
for(int i=2;i<n;i++){
campo[i-1].first=campo[i].first;
}
campo[n-1].first=aux;
}
int comprueba(int pos){
int it=0;
campo.clear();
campo.resize(n,{0,0});
posciciones.clear();
posciciones.resize(n*2+2,0);
campo[pos].first=habilidades[0];
for(int i=1;i<n*2;i++){
if(campo[it].first==0){
campo[it].first=habilidades[i];
posciciones[i]=it;
}else if(campo[it].second==0){
campo[it].second=habilidades[i];
posciciones[i]=it;
}else{
it++;
i--;
}
}
for(int i=1;i<=2*n;i++){
ronda();
}
int acomodo=0;
for(int i=0;i<n;i++){
if(campo[i].first==yo or campo[i].second==yo)acomodo=i;
}
int restantes=r-2*n;
restantes%=n;
acomodo-=restantes;
acomodo+=n;
acomodo%=n;
return acomodo;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>r;
habilidades.resize(n*2+2,0);
campo.resize(n+2,{0,0});
for(int i=0;i<n*2;i++)cin>>habilidades[i];
yo=habilidades[0];
int ans=-1;
int minima=INT_MAX;
//cout<<"xd\n";
for(int i=0;i<n;i++){
int res=comprueba(i);
//for(auto x:campo)cout<<x.first<<' '<<x.second<<'\n';
//cout<<res<<'\n';
if(res<=minima){ans=i; minima=res;}
}
cout<<ans+1<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |