Submission #1216744

#TimeUsernameProblemLanguageResultExecution timeMemory
1216744takoshanavaRice Hub (IOI11_ricehub)C++20
Compilation error
0 ms0 KiB
#include "ricehub.h"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fs first
#define sc second

int besthub(int R, int L, int X[], long long B)
{
  vector<int> pref(r + 1, 0);
    for (int i = 0; i < r; ++i) {
        pref[i + 1] = pref[i] + x[i];
    }

    int ans = 1;
    int ll = 1, rr = r;

    while (ll <= rr) {
        int mid = (ll + rr) / 2;
        bool ok = false;

        for (int i = 0; i + mid <= r; ++i) {
            int s = i;
            int t = i + mid - 1;
            int p = (s + t) / 2;
            int rp = x[p];

            int lcnt = p - s;
            int lsum = pref[p] - pref[s];

            int rcnt = t - p;
            int rsum = pref[t + 1] - pref[p + 1];

            int cost = (rp * lcnt - lsum) + (rsum - rp * rcnt);

            if (cost <= b) {
                ok = true;
                break;
            }
        }

        if (ok) {
            ans = x[mid - 1];
            ll = mid + 1;
        } else {
            rr = mid - 1;
        }
    }

    return ans;
}

Compilation message (stderr)

ricehub.cpp: In function 'long long int besthub(long long int, long long int, long long int*, long long int)':
ricehub.cpp:10:3: error: 'vector' was not declared in this scope
   10 |   vector<int> pref(r + 1, 0);
      |   ^~~~~~
ricehub.cpp:10:3: note: suggested alternatives:
In file included from /usr/include/c++/11/vector:67,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from ricehub.cpp:2:
/usr/include/c++/11/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from ricehub.cpp:2:
/usr/include/c++/11/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
ricehub.cpp:3:13: error: expected primary-expression before 'long'
    3 | #define int long long
      |             ^~~~
ricehub.cpp:10:10: note: in expansion of macro 'int'
   10 |   vector<int> pref(r + 1, 0);
      |          ^~~
ricehub.cpp:11:25: error: 'r' was not declared in this scope
   11 |     for (int i = 0; i < r; ++i) {
      |                         ^
ricehub.cpp:12:9: error: 'pref' was not declared in this scope
   12 |         pref[i + 1] = pref[i] + x[i];
      |         ^~~~
ricehub.cpp:12:33: error: 'x' was not declared in this scope
   12 |         pref[i + 1] = pref[i] + x[i];
      |                                 ^
ricehub.cpp:16:22: error: 'r' was not declared in this scope
   16 |     int ll = 1, rr = r;
      |                      ^
ricehub.cpp:26:22: error: 'x' was not declared in this scope
   26 |             int rp = x[p];
      |                      ^
ricehub.cpp:29:24: error: 'pref' was not declared in this scope
   29 |             int lsum = pref[p] - pref[s];
      |                        ^~~~
ricehub.cpp:36:25: error: 'b' was not declared in this scope
   36 |             if (cost <= b) {
      |                         ^
ricehub.cpp:43:19: error: 'x' was not declared in this scope
   43 |             ans = x[mid - 1];
      |                   ^