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;
int n;
long long counter = 0;
long long count_swaps(vector<int> s) {
n = s.size()/2;
if (n > 2500)
{
n = s.size()/2;
int minusPos = 0;
for (int i = 0; i < 2 * n; i++)
{
if (s[i] < 0)
{
counter += abs(i - minusPos);
minusPos += 2;
}
}
return counter;
}
for (int i = 0; i < n; i++)
{
int x = -s[2 * i];
int pos = -1;
for (int j = 2 * i + 1; j < 2 * n; j++)
{
if (s[j] == x)
{
pos = j;
break;
}
}
for (int j = pos; j > 2 * i + 1; j--)
{
swap(s[j], s[j-1]);
counter++;
}
if (x < 0)
{
counter++;
}
//cout << "After pair " << i << " count is " << counter << "\n";
}
return counter;
}
# | 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... |