# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
667781 | coding_snorlax | Arranging Shoes (IOI19_shoes) | C++14 | 0 ms | 0 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<bits/stdc++.h>
#include "shoes.h"
using namespace std;
long long int count_swaps(vector<int> s){
int now=s[0];
int time=0;
long long int Count_answer=0;
for(int k=0;k<(int)s.size()/2;k++){
for(int i=time;i<(int)s.size();i++){
if(s[i]==-now){
//cout<<i<<" "<<time<<endl;
if(s[time]>0) Count_answer+=i-time;
else Count_answer+=i-time-1;
for(int j=time;j<i;j++){
int tmp=s[j];
s[j]=s[j+1];
s[j+1]=tmp;
}
break;
}
}
time+=2;
now=s[time];
}
return Count_answer;
}
int main(){
vector<int> s={-2,2,2,-2,-2,2};
cout<<count_swaps(s);
}