Submission #397877

#TimeUsernameProblemLanguageResultExecution timeMemory
397877snasibov05Arranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h"
#include <set>

using namespace std;

long long count_swaps(vector<int> s) {

    long long ans = 0;
    int n = s.size();
    set<int> st;
    for (int i = 1; i < n; i += 2) {
        if (s[i] < 0) st.insert(i);
    }

    for (int i = 0; i < n; i += 2) {
        ans += abs(*st.begin() - i);
        st.erase(st.begin());
    }

    return ans;

}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:16:16: error: 'abs' was not declared in this scope; did you mean 'ans'?
   16 |         ans += abs(*st.begin() - i);
      |                ^~~
      |                ans