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 = 2e5+45;
int 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){
int poz = 0;
for(int j = i+1; j <= n; j++){
if(a[j] == -a[i]){
poz = j;
break;
}
}
for(int j = poz; j > i+1; j--){
sol++;
swap(a[j],a[j-1]);
}
if(a[i] > 0 && a[i+1] < 0){
swap(a[i],a[i+1]);
sol++;
}
}
return sol;
}
/*int main(){
vector <int> s;
int x;
cin >> x;
while(x--){
int y;
cin >> y;
s.push_back(y);
}
cout << count_swaps(s) << 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... |