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;
typedef long long ll;
const int N = 1e5+45;
ll n,a[N];
ll count_swaps(vector <int> S){
n = S.size();
for(int i = 1; i <= n; i++){
a[i] = S[i-1];
}
ll sol = 0;
for(int i = 1; i <= n; i += 2){
ll poz = 0;
for(int j = i+1; j <= n; j++){
if(a[i]+a[j] == 0){
poz = j;
break;
}
}
for(int j = poz-1; j > i; j--){
swap(a[j],a[j+1]);
sol++;
}
if(a[i] > 0){
swap(a[i],a[i+1]);
sol++;
}
}
return sol;
}
/*int main(){
vector <int> v = {-2, 2, 2, -2, -2, 2};
cout << count_swaps(v) << endl;
}*/
# | 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... |