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 <set>
using namespace std;
#define ll long long
set<int> shoes[200000];
int n;
int dist[200000];
ll get_dist(int idx){
ll d=0;
for(int i=0;i<idx;i++)
d+=dist[i];
return d;
}
ll count_swaps(vector<int> s) {
n = s.size();
for(int i=0;i<n;i++)
shoes[s[i]+100000].insert(i);
for(int i=0;i<n;i++)
dist[i]=1;
ll res=0;
int pos1=0;
while(pos1<n){
int pos2=*shoes[100000-s[pos1]].begin();
res+=get_dist(pos2);
if(s[pos1]<0)
res--;
dist[pos1]=0;
dist[pos2]=0;
shoes[100000-s[pos1]].erase(shoes[100000-s[pos1]].begin());
shoes[100000+s[pos1]].erase(shoes[100000+s[pos1]].begin());
while(dist[pos1]==0) pos1++;
}
return res;
}
| # | 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... |