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 "shoes.h"
#include <bits/stdc++.h>
using namespace std;
long long count_swaps(std::vector<int> s) {
if(s.size() > 2000){
long long ans = 0;
priority_queue<int, vector<int>, greater<int>> l, r;
for(int i = 0; i < (int)s.size(); ++i){
if(s[i] < 0) l.push(i);
else r.push(i);
}
for(int i = 0; i < (int)s.size(); ++i){
if(i%2 == 0){
if(s[i] > 0){
ans += l.top() - i;
swap(s[i], s[l.top()]);
r.pop();
r.push(l.top());
}
l.pop();
}else {
if(s[i] < 0){
ans += r.top() - i;
swap(s[i], s[r.top()]);
l.pop();
l.push(r.top());
}
r.pop();
}
}
return ans;
}
long long ans = 0;
for(int i = 0; i < (int)s.size(); i += 2){
if(s[i] < 0){
for(int j = i+1; j < (int)s.size(); ++j){
if(s[j] == -s[i]){
for(int k = j; k > i+1; --k){
swap(s[k], s[k-1]);
ans++;
}
break;
}
}
}else {
int target = -s[i];
for(int j = i+1; j < (int)s.size(); ++j){
if(s[j] == target){
for(int k = j; k > i; --k){
swap(s[k], s[k-1]);
ans++;
}
break;
}
}
}
}
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... |