#include "shoes.h"
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
long long count_swaps(vector<int> S) {
long long swaps = 0;
int n = S.size();
for (int i = 0; i < n; ) {
if (S[i] < 0) {
// Skip right shoes — can't start a pair
++i;
continue;
}
int size = S[i];
// Find matching right shoe
int j = i + 1;
while (j < n && S[j] != -size) {
++j;
}
// Move the right shoe leftward to i + 1
while (j > i + 1) {
swap(S[j], S[j - 1]);
--j;
++swaps;
}
// Now valid pair at i, i+1
i += 2;
}
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... |