# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1011684 | u_suck_o | Arranging Shoes (IOI19_shoes) | C++17 | 1080 ms | 3536 KiB |
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(vector<int> s) {
long long ans = 0;
long long n = s.size()/2;
long long minloc[n+1][2];
for (int p = 0; p < n; p++) {
memset(minloc, 0x3f, sizeof minloc);
for (long long i = 0; i < s.size(); i++) {
if (s[i] < 0)
minloc[-s[i]][0] = min(minloc[-s[i]][0], i);
else
minloc[s[i]][1] = min(minloc[s[i]][1], i);
}
long long mind = LONG_LONG_MAX, mini = -1;
for (int i = 1; i <= n; i++) {
long long d = minloc[i][0] + minloc[i][1] - 1;
if (minloc[i][0] > minloc[i][1]) d += 1;
if (d < mind) {
mind = d;
mini = i;
}
}
ans += mind;
s.erase(s.begin() + max(minloc[mini][0], minloc[mini][1]));
s.erase(s.begin() + min(minloc[mini][0], minloc[mini][1]));
}
return ans;
}
Compilation message (stderr)
# | 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... |