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(vector<int> s) {
int n=(int)s.size();
vector<int>vp(n);
for(int i=0;i<n;i++){
if(s[i]<0)
vp[i]=0;
else
vp[i]=1;
}
long long cost=0;
set<int>left;
set<int>right;
for(int i=0;i<n;i++){
if(vp[i]==0){
if(i%2==0)
continue;
if(!right.empty()) {
cost += i -*right.begin();
right.erase(right.begin());
}
else
left.insert(i);
}
else{
if(i%2==1)
continue;
if(!left.empty()){
cost+=i-*left.begin();
left.erase(left.begin());
}
else
right.insert(i);
}
}
return cost;
}
# | 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... |