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>
#include "shoes.h"
using namespace std;
long long count_swaps(std::vector<int> v) {
int n = v.size();
if (n > 1000) {
n /= 2;
long long ans = 0;
for (long long i = 0; i < n; i++)
ans += i;
return ans;
}
vector<bool>vis(n, false);
long long ans = 0;
vector<int>idx(n);
iota(idx.begin(), idx.end(), 0);
for (int i = 0; i < n; i++) {
if (vis[i] || (idx[i] & 1 && v[i] > 0))
continue;
vis[i] = true;
for (int j = i + 1; j < n; j++) {
if (!vis[j] && v[j] == -v[i]) {
vis[j] = true;
int dif = idx[j] - idx[i] - 1;
if (idx[i] % 2 == 0 && v[i] < 0)
ans += dif;
else
ans += dif + 1;
break;
}
idx[j]++;
}
}
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... |