Submission #1268835

#TimeUsernameProblemLanguageResultExecution timeMemory
1268835FaresSTHArranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 KiB
#include"bits/stdc++.h"
using namespace std;
using ll=long long;

ll count_swaps(const vector<int>& a){
    int n = (int)a.size();
    vector<int> neg;
    neg.reserve(n);
    for (int i=0;i<n;i++) if (a[i] < 0) neg.push_back(i);

    auto cost = [&](int start)->long long { // start = 0 (even) or 1 (odd)
        vector<int> tgt;
        for (int i=start;i<n;i+=2) tgt.push_back(i);
        if (tgt.size() != neg.size()) return (long long)4e18; // impossible for this pattern
        long long res = 0;
        for (size_t k=0;k<neg.size();++k) res += llabs((long long)neg[k] - tgt[k]);
        return res;
    };

    long long ans = min(cost(0), cost(1));
    // If both patterns are impossible, return -1 (if your task wants that),
    // otherwise return 'ans'.
    if (ans >= (long long)3e18) return -1;
    return ans;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/cc4PetQG.o: in function `main':
grader.cpp:(.text.startup+0x26b): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status