Submission #1187079

#TimeUsernameProblemLanguageResultExecution timeMemory
1187079eri16Arranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 KiB
#include "shoes.h"

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

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

Compilation message (stderr)

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