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;
#include "shoes.h"
long long count_swaps(std::vector<int> s) {
int n = (int)s.size() / 2;
int N = 2 * n;
long long ans = 0;
for(int pos = 0; pos < n; pos++) {
//printf("pos = %d\n", pos);
int target = -s[2 * pos];
int fnd = -1;
for(int i = 2 * pos + 1; i < N; i++) {
if(s[i] == target) {
fnd = i;
break;
}
}
assert(fnd + 1);
for(int i = fnd - 1; i >= 2 * pos + 1; i--) {
swap(s[i], s[i + 1]);
ans += 1;
}
if(s[2 * pos] > 0) {
swap(s[2 * pos], s[2 * pos + 1]);
ans += 1;
}
//printf("ans = %d\n", 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... |