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(vector<int> s){
int n = s.size()/2;
long long ans = 0;
for(int i = 0;i<n;i++){
int val1 = 1e9;
int val2 = 1e9;
for(int j = 2*i;j<2*n;j++){
if(s[j] == -s[2*i]){
val1 = j - (2 * i) - 1 + (s[j] < 0);
break;
}
}
for(int j = 2*i + 1;j<2*n;j++){
if(s[j] == -s[2*i + 1]){
val2 = j - (2 * i) + (s[j] < 0);
break;
}
}
// cout << val1 << ' ' << val2 << endl;
ans += min(val1,val2);
if(val2 < val1){
swap(s[2*i],s[2*i+1]);
}
for(int j = 2*i+1;j<2*n;j++){
if(s[j] == -s[2*i]){
for(int c = j;c>2*i + 1;c--){
swap(s[c],s[c-1]);
}
break;
}
}
if(s[2*i] > 0)
swap(s[2*i+1],s[2*i]);
// for(auto u:s){
// cout << u << ' ';
// }
// cout << endl;
}
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... |