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"
using namespace std;
#define ll long long
ll count_swaps(vector<int> v){
// for subtask 4
int n = (int)v.size(), ok = 1;
n /= 2;
for(int i = 0; i < n; ++i)
ok &= (v[i] < 0);
for(int i = 0; i < n; ++i)
ok &= (-v[i] == v[i+n]);
// if v[0...n-1] is all left, it means v[n...2*n-1] is all right
if(ok){
ll answer = n*1ll*(n+1)/2;
return answer;
}
n *= 2;
ll answer = 0;
for(int i = 0; i < n-1; i+=2){
if(-v[i] == v[i+1]){
// if v[i] and v[i+1] are same size
if(v[i] > 0){
// it means if v[i] is right shoes
answer++;
swap(v[i], v[i+1]);
}
}
else{
// is it isn't same size
int ad = -1;
for(int j = i+1; j < n; ++j)
if(v[i] == -v[j]){
ad = j;
break;
}
// we find a pair of that shoe
for(int j = ad; j > i+1; --j){
answer++;
swap(v[j], v[j-1]);
}
if(v[i] > 0){
answer++;
swap(v[i], v[i+1]);
// it means v[i] is right shoes
}
}
}
return answer;
}
# | 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... |