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;
#define ll long long
#define pb push_back
#define mp make_pair
vector<pair<int, int> > lft;
map<int, queue<int> > rgt;
long long count_swaps(vector<int> s) {
//nums
ll n = s.size()/2;
ll S = s.size();
//iterate through s -- preprocess
for( int i = 0; i < S; i++ ){
if( s[i] < 0 ){ lft.pb( mp(s[i], i) ); } //left shoe
else if ( s[i] > 0 ){ rgt[s[i]].push(i); } //right shoe
}
bool idim[S];
memset( idim, true, sizeof idim );
//process
ll grand = 0;
for( int i = 0; i < n; i++ ){
for( int j = 0; j < lft[i].second; j++ ){ grand += idim[j]; }
idim[ lft[i].second ] = false;
for( int j = 0; j < rgt[ abs(lft[i].first) ].front(); j++){ grand += idim[j]; }
idim[ rgt[abs(lft[i].first)].front() ] = false;
rgt[abs(lft[i].first)].pop();
}
return grand;
}
# | 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... |