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 "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
long long count_swaps(std::vector<int> s) {
ll n = s.size();
bool flag = true;
ll ans = 0;
for(ll i = 0; i < n/2; i++){
if(s[i] != -s[n/2 + i] || s[i] > 0){
flag = false;
break;
}
}
if(flag && n > 2){
ll x = (n/2)*(n/2 - 1)/2;
return x;
}
for(ll i = 0; i < n; i++){
ll cur = s[i];
ll l = -1;
for(ll j = i - 1; j >= 0; j--){
if(s[j] == -cur) l = j;
}
if(l != -1){
ans += (i - l - (s[i] > 0));
for(ll j = i; j > l; j--) swap(s[j], s[j - 1]);
s[l] = s[l + 1] = 0;
}
}
return ans;
}
/*int main(){
int n;
scanf("%d",&n);
vector<int>arr(n);
for(int i=0;i<n;i++) scanf("%d",&arr[i]);
printf("%d\n",count_swaps(arr));
return 0;
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |