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 <vector>
#include <cstdio>
#include <string>
#include <set>
#include <cstdlib>
#include <iostream>
#include <map>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int (i) = 0; (i) < (n); (i)++)
long long count_swaps(vector<int> a)
{
long long ans = 0;
int n = a.size();
for (int i = 0; i < n; i += 2)
{
map<int, int> hv;
int p1 = 0, p2 = 0;
for (int j = i; j < n; j++)
{
hv[a[j]] = j;
if (hv.find(-a[j]) != hv.end())
{
p1 = hv[-a[j]];
p2 = j;
break;
}
}
while (p1 != i)
{
swap(a[p1 - 1], a[p1]);
p1--;
ans++;
}
while (p2 != i + 1)
{
swap(a[p2 - 1], a[p2]);
p2--;
ans++;
}
if (a[p1] > a[p2])
{
swap(a[p1], a[p2]);
ans++;
}
}
return ans;
}
# | 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... |