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;
#define ll long long
ll count_swaps(vector<int> a) {
ll ans = 0; int n = (int)a.size();
for (int i = 0; i < n; ) {
while (i < n && -a[i] == a[i + 1]) {
if (a[i + 1] < a[i]) {
swap(a[i + 1], a[i]); ++ans;
}
i += 2;
}
if (i >= n) break;
int j = i + 2;
while (-a[j] != a[i]) {
++j;
}
for (; j > i + 1; j--) {
swap(a[j], a[j - 1]);
++ans;
}
if (a[i + 1] < a[i]) {
swap(a[i + 1], a[i]); ++ans;
}
}
return ans;
}
# | 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... |