# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1040061 | LaMatematica14 | Arranging Shoes (IOI19_shoes) | C++17 | 37 ms | 7224 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>
using namespace std;
long long count_swaps(vector<int> S) {
vector<int> fat(10, 1);
for (int i = 1; i < 10; i++) fat[i] = fat[i-1]*i;
int n = S.size();
vector<int> c = S;
sort(c.rbegin(), c.rend());
vector<int> sz(n/2);
for (int i = 0; i < n/2; i++) sz[i] = c[i];
long long best = 1e9;
for (int j = 0; j < fat[n/2]; j++) {
long long tot = 0;
next_permutation(sz.begin(), sz.end());
vector<queue<int>> a(n);
for (int i = 0; i < n/2; i++) {
a[sz[i]].push(2*i);
}
vector<int> pa(n);
int att = 0;
for (long long i = 0; i < n; i++) {
if (S[i] < 0) {
pa[i] = a[-S[i]].front();
a[-S[i]].pop();
a[-S[i]].push(pa[i]);
}
}
for (long long i = 0; i < n; i++) {
if (S[i] > 0) {
pa[i] = a[S[i]].front()+1;
a[S[i]].pop();
}
}
for (long long i = 0; i < n; i++) {
for (long long j = i+1; j < n; j++) {
if (pa[i] > pa[j]) tot++;
}
}
best = min(best, tot);
}
return best;
}
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... |