# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
912463 | agusss | Arranging Shoes (IOI19_shoes) | C++14 | 0 ms | 0 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.
long long count_swaps(std::vector<int> s) {
vector<bool> used(s.size(), false);
long long cnt = 0;
// cout << "size:" << s.size() << "\n";
for (int i = 0; i < s.size(); i++) {
int j;
if (used[i]) {
continue;
}
// cout << "to pair" << i << "\n";
for (j = i + 1; j < s.size(); j++) {
if (s[j] == -s[i] and !used[j]) {
used[j] = true;
break;
}
}
if (j < s.size()) {
// cout << i << ", " << j << "\n";
long long distance = j - i - (s[i] < 0 ? 1 : 0);
cnt += distance;
}
}
return cnt;
}