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 <bits/stdc++.h>
#include "shoes.h"
using namespace std;
long long count_swaps(std::vector<int> s) {
bool der = false;
int ans = 0;
int n = s.size();
for(int i = 0 ; i < n; i++){
der = false;
//for(auto x : s) cout<<x<<" ";
//cout<<endl;
//cout<<s[i]<<" +++++++++ "<<i<<endl;
if(s[i] > 0) der = true;
int pos = INT_MAX;
int m = s.size();
for(int j = i+1; j < m; j++){
if(abs(s[i]) == abs(s[j])){
pos = j;
s.erase(s.begin() + j);
break;
}
}
//cout<<der<<" "<<i<<" "<<pos<<endl;
if(pos == INT_MAX) continue;
if(der && pos == i+1){
ans += 1;
continue;
}
if(pos == i + 1 && !der){
continue;
}
if(der) ans += abs(i - pos);
else ans += abs(i - pos) - 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... |