# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
670032 | haxorman | Arranging Shoes (IOI19_shoes) | C++14 | 1 ms | 300 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"
#include <bits/stdc++.h>
using namespace std;
long long count_swaps(vector<int> vec) {
map<int,vector<int>> pos;
for (int i = 0; i < vec.size(); ++i) {
pos[vec[i]].push_back(i);
}
int ans = 0;
for (int i = 0; i < vec.size() - 1; ++i) {
/*
cout << vec[i] << "\n";
for (auto x : pos[-vec[i]]) {
cout << x << ' ';
}
cout << "\n---\n";
*/
auto it = upper_bound(pos[-vec[i]].begin(), pos[-vec[i]].end(), i);
ans += *it - i;
if (vec[i] < 0) {
--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... |