Submission #587244

# Submission time Handle Problem Language Result Execution time Memory
587244 2022-07-01T14:15:16 Z jakubd Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include "candies.h"

#include <bits/stdc++.h>

using namespace std;

#define int long long

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
  int n = c.size(), q = (int)l.size();
  vector<int> s;

  if (n <= 2000 && q <= 2000) {
    s.resize(n);

    for (int i = 0; i < q; i++) {
      for (int j = l[i]; j <= r[i]; j++) {
        s[j] += v[i];

        if (s[j] < 0) s[j] = 0;
        if (s[j] > c[j]) s[j] = c[j];
      }
    }
  } else {
    s.resize(n + 1);

    for (int i = 0; i < q; i++) {
      s[l[i]] += v[i];
      s[r[i] + 1] -= v[i];
    }

    for (int i = 0; i < n; i++) s[i + 1] += s[i];

    vector<int> res(n);
    for (int i = 0; i < n; i++) {
      res[i] = min(s[i + 1], c[i]);
    }
  }

  return s;
}

Compilation message

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