Submission #332379

#TimeUsernameProblemLanguageResultExecution timeMemory
332379thecodingwizardWiring (IOI17_wiring)C++11
Compilation error
0 ms0 KiB
#include "wiring.h"
#include <bits/stdc++.h>

using namespace std;

#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define inf 1000000010
#define int long long

set<int> wires[2];
int dp[200000];

int getClosest(int x, int t) {
    auto it = wires[t].lower_bound(x);
    int best = inf;
    if (it != wires[t].end()) {
        best = min(best, *it-x);
    }
    if (it != wires[t].begin()) {
        best = min(best, x-*prev(it));
    }
    return best;
}

long long min_total_length(vector<int> r, vector<int> b) {
    for (int x : r) wires[0].insert(x);
    for (int x : b) wires[1].insert(x);

    vector<ii> A;
    for (int x : r) A.pb(mp(x, 0));
    for (int x : b) A.pb(mp(x, 1));

    sort(all(A));

    int prevBlockIdx = -1;
    int prevBlockSum = 0;
    for (int i = 0; i < (int)A.size(); i++) {
        dp[i] = (i==0?0:dp[i-1]) + getClosest(A[i].f, !A[i].s);

        if (i == 0 || A[i].s != A[i-1].s) {
            prevBlockIdx = i-1;
            prevBlockSum = 0;
        }
        if (prevBlockIdx != -1 && A[prevBlockIdx].s != A[i].s) {
            prevBlockSum += A[i].f - A[prevBlockIdx].f;
            prevBlockIdx--;
            dp[i] = min(dp[i], (prevBlockIdx>=0?dp[prevBlockIdx]:0) + prevBlockSum);
        }
    }

    return dp[A.size()-1];
}

Compilation message (stderr)

/tmp/ccq3VLyt.o: In function `main':
grader.cpp:(.text.startup+0x258): undefined reference to `min_total_length(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status