# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
423578 | schse | Arranging Shoes (IOI19_shoes) | C++17 | 1121 ms | 273860 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 "shoes.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
long long count_swaps(std::vector<int> s)
{
vector<int> posadd(s.size());
vector<bool> sorted(s.size(), false);
vector<queue<int>> pleft(s.size() + 1), pright(s.size() + 1);
iota(posadd.begin(), posadd.end(), 0);
long long numswaps = 0;
for (int i = 0; i < s.size(); i++)
(s[i] > 0 ? pright : pleft)[abs(s[i])].push(i);
for (int e, i = 0; i < s.size(); i++)
{
if (sorted[i])
continue;
(s[i] > 0 ? pright : pleft)[abs(s[i])].pop();
e = (s[i] < 0 ? pright : pleft)[abs(s[i])].front();
(s[i] < 0 ? pright : pleft)[abs(s[i])].pop();
sorted[i] = sorted[e] = true;
for (int c = i + 1; c < e; c++)
posadd[c]++;
numswaps += posadd[e] - posadd[i] - 1;
if (s[i] > 0)
numswaps++;
}
return numswaps;
}
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... |