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;
ll count_swaps(vector<int>v){
ll n = v.size();
bool st4 = true;
ll ans = 0;
for(ll i = 0; i < n/2; i++){
if(v[i] != -v[n/2 + i] || v[i] > 0){
st4 = false;
break;
}
}
if(st4 && n > 2){
ll x = (n/2)*(n/2 - 1)/2;
return x;
}
for(ll i = 0; i < n; i++){
ll cur = v[i];
ll l = -1;
for(ll j = i - 1; j >= 0; j--){
if(v[j] == -cur) l = j;
}
if(l != -1){
ans += (i - l - (v[i] > 0));
for(ll 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;
// }
# | 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... |