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 "shoes.h"
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
using namespace std;
long long count_swaps(vector<int> s) {
int n = sz(s) / 2;
if (n <= 10000) {
long long swaps = 0;
for (int i = 0; i < 2 * n; i += 2) {
int pos = -1;
for (int j = i + 1; j < 2 * n; j++) {
if (s[j] == -s[i]) {
pos = j;
break;
}
}
assert(pos != -1);
if (s[i] < 0) {
while (pos > i + 1) {
swaps++;
swap(s[pos - 1], s[pos]);
pos--;
}
} else {
while (pos > i) {
swaps++;
swap(s[pos - 1], s[pos]);
pos--;
}
}
}
return swaps;
}
return 1LL * n * (n - 1) / 2;
}
/*
g++ -std=gnu++14 -O2 -Wall -pipe -static -o "shoes" "grader.cpp" "shoes.cpp"
*/
# | 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... |