Submission #1224952

#TimeUsernameProblemLanguageResultExecution timeMemory
1224952im2xtremeArranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 KiB
#include <iostream>
#include <vector>
#include <cmath>
#include "shoes.h"
using namespace std;

int64_t count_swaps(vector<int> S) {
    int64_t 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;

        // Now move S[j] to position i+1 via adjacent swaps
        while (j > i + 1) {
            swap(S[j], S[j - 1]);
            swaps++;
            j--;
        }
        // i+1 now contains the right shoe
        // Skip next index as it's already a valid pair
        i++;
    }

    return swaps;
}

Compilation message (stderr)

shoes.cpp:7:9: error: ambiguating new declaration of 'int64_t count_swaps(std::vector<int>)'
    7 | int64_t count_swaps(vector<int> S) {
      |         ^~~~~~~~~~~
In file included from shoes.cpp:4:
shoes.h:7:11: note: old declaration 'long long int count_swaps(std::vector<int>)'
    7 | long long count_swaps(std::vector<int> S);
      |           ^~~~~~~~~~~