# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1272955 | arkanefury | Arranging Shoes (IOI19_shoes) | C++20 | 0 ms | 0 KiB |
#include "shoes.h"
using namespace std;
const int N = 2e5+5;
int a[N], b[N];
long long count_swaps(vector <int> v){
int n = v.size(), k;
long long ans = 0;
for(int i = 0; i < n; i += 2){
if(v[i] < 0){
for(int j = i+1; j < n; i ++){
if(v[j] > 0 && v[j] == abs(v[i])){
k = j;break;
}
}
for(int j = k; j > i+1; j --){
swap(a[j], a[j-1]);
ans ++;
}
}
else{
for(int j = i+1; j < n; i ++){
if(v[j] < 0 && abs(v[j]) == v[i]){
k = j;break;
}
}
for(int j = k; j > i; j --){
swap(a[j], a[j-1]);
ans ++;
}
}
}
return ans;
}