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;
int vs[1001];
long long count_swaps(vector<int>s) {
long long n = s.size(); long long ans = 0;
for(int i = 0; i < n; i++){
int f = 0;
for(int j = 0; j < i; j++){
if(!vs[j] && s[i] == -s[j]){
f = j + 1;
break;
}
}
if(f && s[i] > 0){
f--;
vs[f] = 1;
if(s[f] < 0) ans += (i - f - 1);
else ans += (i - f);
int y = s[i];
for(int j = i - 1; j > f; j--){
s[j + 1] = s[j];
}
vs[f + 1] = 1;
s[f + 1] = y;
if(s[f] > 0) swap(s[f], s[f + 1]);
}
}
for(int i = 0; i < n; i++){
int f = 0;
for(int j = 0; j < i; j++){
if(!vs[j] && s[i] == -s[j]){
f = j + 1;
break;
}
}
if(f && s[i] < 0){
f--;
vs[f] = 1;
if(s[f] < 0) ans += (i - f - 1);
else ans += (i - f);
int y = s[i];
for(int j = i - 1; j > f; j--){
s[j + 1] = s[j];
}
vs[f + 1] = 1;
s[f + 1] = y;
if(s[f] > 0) swap(s[f], s[f + 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... |