# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
826732 | kevinsogo | Arranging Shoes (IOI19_shoes) | C++17 | 1090 ms | 32536 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;
#include "shoes.h"
using ll = long long;
ll count_swaps(vector<int> _seq) {
unordered_map<ll,int> found;
vector<ll> seq, aseq;
for (int v : _seq) seq.push_back(ll(v) * _seq.size() + ((v > 0) - (v < 0)) * found[v]++);
unordered_map<ll,int> pos;
for (int i = 0; i < seq.size(); i++) pos[seq[i]] = i;
for (ll v : seq) if (v > 0) aseq.push_back(v);
sort(aseq.begin(), aseq.end(), [&](int i, int j) {
int d = min(pos[i], pos[-i]) - min(pos[j], pos[-j]);
return d ? d < 0 : i < j;
});
vector<int> targ;
for (int v : aseq) for (int s : {-1, +1}) targ.push_back(pos[s * v]);
ll ans = 0;
for (int j = 0; j < targ.size(); j++) {
for (int i = 0; i < j; i++) if (targ[i] > targ[j]) ans++;
}
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... |