#include <iostream>
#include <vector>
#include <algorithm> // for std::swap
#include "shoes.h"
using namespace std;
long long count_swaps(vector<int> S) {
long long swaps = 0;
int n = S.size();
for (int i = 0; i < n; ++i) {
if (S[i] < 0) continue; // Skip right shoes
// S[i] is a left shoe
int size = S[i];
// Find matching right shoe -size
int j = i + 1;
while (j < n && S[j] != -size) ++j;
// Move S[j] to position i+1 via adjacent swaps
while (j > i + 1) {
swap(S[j], S[j - 1]);
swaps++;
j--;
}
// Skip the next position (it's part of the matched pair now)
i++;
}
return swaps;
}
# | 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... |