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"
#include "shoes.h"
using namespace std;
long long count_swaps(vector<int> s) {
long long ans = 0;
long long n = s.size()/2;
int p1 = 1, p2 = 1;
for (int i = 0; i < 2*n; i++) {
p1 = max(i+1, p1);
p2 = max(i+1, p2);
if (i % 2 == 0) {
if (s[i] < 0)
continue;
while (s[p1] > 0) p1++;
swap(s[i], s[p1]);
ans += p1 - i;
}
if (i % 2 == 1) {
if (s[i] > 0)
continue;
while (s[p2] < 0) p2++;
swap(s[i], s[p2]);
ans += p2 - i;
}
}
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... |