Submission #1257451

#TimeUsernameProblemLanguageResultExecution timeMemory
1257451huydeptraiso1vutruvnArranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 KiB
#include <iostream>
#include <vector>
using namespace std;

int minSwapsToPairShoes(int n, vector<int>& shoes) {
    int totalSwaps = 0;
    int len = 2 * n;

    for (int i = 0; i < len; i += 2) {
        // Nếu vị trí i là giày phải, ta cần tìm giày trái phù hợp
        if (shoes[i] > 0) {
            for (int j = i + 1; j < len; ++j) {
                if (shoes[j] == -shoes[i]) {
                    // Đưa shoes[j] về vị trí i
                    for (int k = j; k > i; --k) {
                        swap(shoes[k], shoes[k - 1]);
                        totalSwaps++;
                    }
                    break;
                }
            }
        }

        // Giờ vị trí i là giày trái, kiểm tra i+1 là giày phải tương ứng
        if (shoes[i + 1] != -shoes[i]) {
            for (int j = i + 2; j < len; ++j) {
                if (shoes[j] == -shoes[i]) {
                    // Đưa shoes[j] về vị trí i+1
                    for (int k = j; k > i + 1; --k) {
                        swap(shoes[k], shoes[k - 1]);
                        totalSwaps++;
                    }
                    break;
                }
            }
        }
    }

    return totalSwaps;
}

int main() {
    int n;
    cin >> n;
    vector<int> shoes(2 * n);
    for (int i = 0; i < 2 * n; ++i) {
        cin >> shoes[i];
    }

    int result = minSwapsToPairShoes(n, shoes);
    cout << result << endl;

    return 0;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccHqYnvg.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccTksnL5.o:shoes.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccHqYnvg.o: in function `main':
grader.cpp:(.text.startup+0x289): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status