# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
532194 | bonk | 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>
using namespace std;
using ll = long long;
const int N = 1e5 + 2;
const int sus = 1e5;
ll count_swaps(vector<int>v){
ll n = v.size();
bool st2 = true;
ll ans = 0;
for(int i = 0; i < n/2; i++){
if(v[i] != -v[n/2 + i]){
st2 = false;
break;
}
}
if(st2){
ll x = (n/2)*(n/2 - 1)/2;
return x;
}
for(int i = 0; i < n; i++){
int cur = v[i];
int l = 1e9;
for(int j = i - 1; j >= 0; j--){
if(v[j] == -cur) l = j;
}
if(l != 1e9){
ans += (i - l) - (v[i] > 0);
for(int j = i; j > l; j--) swap(v[j], v[j - 1]);
v[l] = v[l + 1] = 0;
}
}
return ans;
}
int main(){
int n; cin >> n;
vector<int>arr(n);
for(int i = 0; i < n; i++) cin >> arr[i];
cout << count_swaps(arr) << endl;
return 0;
}