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;
using ll = int64_t;
long long count_swaps(std::vector<int> v) {
const int n = v.size()/2;
ll ret = 0;
for(int i=0;i<n;++i){
const int l = 2*i;
int a = l;
while(v[a] > 0) ++a;
ret += a-l;
rotate(v.begin()+l, v.begin()+a, v.begin()+a+1);
assert(v[l] < 0);
int b = l+1;
while(v[b] != -v[l]) ++b;
ret+=b-l-1;
rotate(v.begin()+l+1, v.begin()+b, v.begin()+b+1);
assert(v[l+1] == -v[l]);
}
return ret;
}
# | 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... |