Submission #81152

#TimeUsernameProblemLanguageResultExecution timeMemory
81152GoodTrungWiring (IOI17_wiring)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define NAME "wiring"
using namespace std;
typedef long long LL;
typedef pair <int, int> pii;
typedef double DB;
typedef pair <LL, LL> pLL;
const int NMAX = 1e6+7;

int64_t min_total_length(vector <int> r, vector <int> b) {
    int64_t res = 0;
    n = r.size();
    m = b.size();
    pii a[NMAX];

    if(r[n-1] < b[0]) {
        for(int i = 0; i < n; ++i)
            res += abs(b[0] - r[i]);
        for(int i = 0; i < m; ++i)
            res += abs(r[n-1] - b[i]);
        return res;
    }

    for(int i = 0; i < n; ++i) {
        a[i].fi = r[i];
        a[i].se = 0;
    }
    for(int i = 0; i < m; ++i) {
        a[i+n].fi = b[i];
        a[i+n].se = 1;
    }
    int nm = n + m;
    sort(a, a + nm);
    int i = 0, j = 0, ck = 0;
    while(i < nm) {
        while(j+1 < nm && a[j+1].se == a[i].se) j++;

        int pos1, pos2;
        if(i > 0) pos1 = a[i-1].fi;
        else pos1 = INT_MAX;
        if(j < nm-1) pos2 = a[j+1].fi;
        else pos2 = INT_MAX;

        for(int t = i; t <= j; ++t)
            res += min(abs(pos1 - a[t].fi), abs(pos2 - a[t].fi));
        if(i > 0 && ck == 1)
            res -= abs(pos1 - a[i].fi);
        if(abs(pos1 - a[j].fi) > abs(pos2 - a[j].fi)) ck = 1;
        else ck = 0;
        j++; i = j;
    }
    return res;
}

int n, m, x[NMAX], y[NMAX], f[NMAX];

/*int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen(NAME".inp", "r", stdin);
    //freopen(NAME".out", "w", stdout);
    cin >> n >> m;
    for(int i = 0; i < n; ++i)
        cin >> x[i];
    for(int i = 0; i < m; ++i)
        cin >> y[i];
    cout << min_total_length(x, y);
}*/

Compilation message (stderr)

wiring.cpp: In function 'int64_t min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:14:5: error: 'n' was not declared in this scope
     n = r.size();
     ^
wiring.cpp:15:5: error: 'm' was not declared in this scope
     m = b.size();
     ^