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) {
long n=s.size();
vector<long>left;
vector<long>right;
bool ok[n]={};
long now=0,arr[n]={},x=0,z,ans=0;
for(long i=0;i<n;i++){
if(s[i]<0){
left.push_back(i);
}
else{
right.push_back(i);
}
}
for(long i=0;i<n;i++){
x+=arr[i];
if(!ok[i]){
if(s[i]<0){
z=right[now];
ok[right[now]]=true;
now++;
arr[i+1]++;
arr[z]--;
ans+=z-x-i-1;
}
else{
ans++;
z=left[now];
ok[left[now]]=true;
now++;
arr[i+1]++;
arr[z]--;
ans+=z-x-i-1;
}
}
}
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... |