Submission #337788

#TimeUsernameProblemLanguageResultExecution timeMemory
337788blueWiring (IOI17_wiring)C++11
Compilation error
0 ms0 KiB
#include "wiring.h"
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
using namespace std;

long long min_total_length(vector<int> r, vector<int> b)
{
    if(r.size() < b.size()) swap(r, b);
    assert(r.size() >= b.size());

    long long res = 0;

    int n = r.size(), m = b.size();

    int rightend[m];
    for(int j = 0; j < m-1; j++) rightend[j] = j;
    rightend[m-1] = n-1;

    for(int j = m-2; j >= 0; j--)
    {
        while(rightend[j+1] - rightend[j] > 1 && abs(r[rightend[j]+1] - b[j]) <= abs(r[rightend[j]+1] - b[j+1]))
            rightend[j]++;
    }

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

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:12:5: error: 'assert' was not declared in this scope
   12 |     assert(r.size() >= b.size());
      |     ^~~~~~
wiring.cpp:7:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
    6 | #include <deque>
  +++ |+#include <cassert>
    7 | using namespace std;