Submission #409572

#TimeUsernameProblemLanguageResultExecution timeMemory
409572600MihneaRice Hub (IOI11_ricehub)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "ricehub.h"

using namespace std;

typedef long long ll;

const int N = 100000 + 7;
int n, len, x[N];
ll b;

deque<int> positions
deque<int> first, second;

ll compute() {
  int x = positions[(int) positions.size() / 2], y;
  if ((int) second.size() == (int) first.size()) {
    y = first.back();
  } else {
    assert((int) second.size() == (int) first.size() + 1);
    y = x;
  }
  assert(x == y);
  ll cost = 0, sum = 0;
  for (auto &p : positions) {
    cost += abs(x - p);
  }
  for (auto &p : first) {
    sum += x - p;
  }
  for (auto &p : second) {
    sum += p - x;
  }
  assert(sum == cost);
  return cost;
}

int besthub(int r, int dim, int rice_fields[], ll gold_coins) {
  n = r;
  len = dim;
  for (int i = 1; i <= n; i++) {
    x[i] = rice_fields[i - 1];
  }
  b = gold_coins;
  int sol = 0;
  for (int i = 1; i <= n; i++) {
    second.push_back(x[i]);
    if ((int) second.size() > (int) first.size()) {
      first.push_back(second.front());
      second.pop_front();
    }
    positions.push_back(x[i]);
    while (compute() > b) {
      positions.pop_front();
      if (first.empty()) {
        second.pop_front();
      } else {
        first.pop_front();
      }
      if ((int) second.size() > (int) first.size()) {
        first.push_back(second.front());
        second.pop_front();
      }
    }
    sol = max(sol, (int) positions.size());
  }
  return sol;
}

Compilation message (stderr)

ricehub.cpp:13:1: error: expected initializer before 'deque'
   13 | deque<int> first, second;
      | ^~~~~
ricehub.cpp: In function 'll compute()':
ricehub.cpp:16:11: error: 'positions' was not declared in this scope
   16 |   int x = positions[(int) positions.size() / 2], y;
      |           ^~~~~~~~~
ricehub.cpp:17:13: error: 'second' was not declared in this scope
   17 |   if ((int) second.size() == (int) first.size()) {
      |             ^~~~~~
ricehub.cpp:17:36: error: 'first' was not declared in this scope
   17 |   if ((int) second.size() == (int) first.size()) {
      |                                    ^~~~~
ricehub.cpp:18:5: error: 'y' was not declared in this scope
   18 |     y = first.back();
      |     ^
ricehub.cpp:21:5: error: 'y' was not declared in this scope
   21 |     y = x;
      |     ^
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from ricehub.cpp:1:
ricehub.cpp:23:15: error: 'y' was not declared in this scope
   23 |   assert(x == y);
      |               ^
ricehub.cpp:28:18: error: 'first' was not declared in this scope
   28 |   for (auto &p : first) {
      |                  ^~~~~
ricehub.cpp:31:18: error: 'second' was not declared in this scope
   31 |   for (auto &p : second) {
      |                  ^~~~~~
ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:47:5: error: 'second' was not declared in this scope
   47 |     second.push_back(x[i]);
      |     ^~~~~~
ricehub.cpp:48:37: error: 'first' was not declared in this scope
   48 |     if ((int) second.size() > (int) first.size()) {
      |                                     ^~~~~
ricehub.cpp:52:5: error: 'positions' was not declared in this scope
   52 |     positions.push_back(x[i]);
      |     ^~~~~~~~~
ricehub.cpp:55:11: error: 'first' was not declared in this scope
   55 |       if (first.empty()) {
      |           ^~~~~
ricehub.cpp:60:39: error: 'first' was not declared in this scope
   60 |       if ((int) second.size() > (int) first.size()) {
      |                                       ^~~~~