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;
//3
//-2 2 2 -2 -2 2
int64_t count_swaps(vector <int> a) {
int n = a.size()/2;
int ans = 0;
for (int i=0; i<2*n-1; i+=2) {
if (abs(a[i])==abs(a[i+1])) continue;
for (int j=i+2; j<2*n; j++) {
if (abs(a[j]) == abs(a[i])) {
ans += j-i-1;
for (int k=j; k>=i+2; k--) {
a[k] = a[k-1];
}
a[i+1] = a[i];
}
}
}
for (int i=0; i<2*n-1; i+=2) {
if (a[i] > 0) ans += 1;
}
return ans;
}
void test () {
int n; cin >> n;
vector<int> a;
for (int i=0; i<2*n; i++) {
int c; cin >> c;
a.push_back(c);
}
cout << count_swaps(a);
}
# | 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... |