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>v) {
int fixed = -1, n = v.size();
long long ans = 0;
while(fixed < n-1) {
int fix = -v[fixed+1];
int pos = fixed+2;
while(pos < n && v[pos] != fix) pos++;
for(int i = pos-1 ; i > fixed+1 ; i--) ans++,swap(v[i],v[i+1]);
if(fix < 0) {
ans++;
swap(v[fixed+1],v[fixed+2]);
}
fixed+=2;
}
return ans;
}
/*
signed main() {
int n; cin>>n;
vector<int>v(n);
for(auto &z : v)
cin >> z;
cout << count_swaps(v);
}
*/
# | 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... |