Submission #1323992

#TimeUsernameProblemLanguageResultExecution timeMemory
1323992sh_qaxxorov_571Arranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;

int64 count_swaps(vector<int> S) {
    int n = S.size();
    int64 res = 0;

    for (int i = 0; i < n; i += 2) {
        int left = abs(S[i]);   // Chap poyabzal o'lchami
        int right = abs(S[i + 1]); // O'ng poyabzal o'lchami

        // 1. Chap poyabzalni topish
        if (S[i] < 0) { 
            int j = i + 1;
            while (j < n && !(S[j] > 0 && abs(S[j]) == left)) j++;
            while (j > i) {
                swap(S[j], S[j - 1]);
                res++;
                j--;
            }
        }

        // 2. O'ng poyabzalni topish
        if (S[i + 1] > 0) {
            int j = i + 2;
            while (j < n && !(S[j] < 0 && abs(S[j]) == right)) j++;
            while (j > i + 1) {
                swap(S[j], S[j - 1]);
                res++;
                j--;
            }
        }
    }

    return res;
}

// Test
int main() {
    vector<int> S1 = {2, 1, -1, -2};
    cout << count_swaps(S1) << endl; // natija: 4

    vector<int> S2 = {-2, 2, 2, -2, -2, 2};
    cout << count_swaps(S2) << endl; // natija: 2

    return 0;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccy9OTgE.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccbHwRHF.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status