Submission #944383

#TimeUsernameProblemLanguageResultExecution timeMemory
944383wiiRobots (IOI13_robots)C++17
Compilation error
0 ms0 KiB
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;

const int MaxN = 5e4 + 5;
int cnt[MaxN], jump[MaxN];
priority_queue<int, vector<int>, greater<int>> q[MaxN];

struct comp {
    bool operator() (int x, int y) {
        if (q[x].size() == q[y].size())
            return x < y;

        return q[x].size() > q[y].size();
    }
};

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    bool impossible = false;

    function<void(int)> pushSize = [&](int s) {
        int id = upper_bound(Y, Y + A, s) - Y;
        if (id < B)
            cnt[id] += 1;
        else impossible = true;
    };

    function<void(int, int)> pushWeight = [&](int w, int s) {
        int id = upper_bound(X, X + A, w) - X;

        if (id < A)
            q[id].push(s);
        else pushSize(s);
    };

    function<int(int, int)> movetoTop = [&](int u, int top) {
        if (u >= A)
            return u;

        if (q[u].size() > top)
            return jump[u] = movetoTop(jump[u], top);
        else
            return u;
    };

    function<void(int)> balance = [&](int lim) {
        for (int i = 0; i < B; ++i) {
            if (cnt[i] > lim)
                cnt[i + 1] += cnt[i] - lim, cnt[i] = lim;
        }

        if (cnt[B] > lim)
            impossible = true;
    };

    sort(X, X + A);
    sort(Y, Y + B);

    for (int i = 0; i < A; ++i)
        jump[i] = i + 1;

    for (int i = 0; i < T; ++i) {
        pushWeight(W[i], S[i]);
    }

    if (impossible)
        return -1;

    set<int, comp> s;
    for (int i = 0; i < A; ++i) if (q[i].size())
        s.insert(i);

    int lst = -1;
    while (!s.empty()) {
        int u = *s.begin(); s.erase(s.begin());
        int v = movetoTop(u, q[u].size() - 1);

        if (lst != q[u].size()) {
            balance(q[u].size() - 1);
            if (impossible)
                return lst;
        }

        lst = q[u].size();

        int Size = q[u].top(); q[u].pop();
        if (v < A) {
            s.erase(v);
            q[v].push(Size);
            s.insert(v);
        } else {
            pushSize(Size);
        }

        if (!q[u].empty())
            s.insert(u);
    }

    return 1;
}

Compilation message (stderr)

robots.cpp: In lambda function:
robots.cpp:40:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |         if (q[u].size() > top)
      |             ~~~~~~~~~~~~^~~~~
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:78:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         if (lst != q[u].size()) {
      |             ~~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/10/map:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from robots.cpp:2:
/usr/include/c++/10/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = comp; _Alloc = std::allocator<int>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type = const std::_Rb_tree_node<int>*]':
/usr/include/c++/10/bits/stl_tree.h:2101:47:   required from 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = comp; _Alloc = std::allocator<int>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::key_type = int]'
/usr/include/c++/10/bits/stl_tree.h:2154:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = const int&; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = comp; _Alloc = std::allocator<int>]'
/usr/include/c++/10/bits/stl_set.h:512:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = int; _Compare = comp; _Alloc = std::allocator<int>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, comp, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = int]'
robots.cpp:71:19:   required from here
/usr/include/c++/10/bits/stl_tree.h:780:8: error: static assertion failed: comparison object must be invocable as const
  780 |        is_invocable_v<const _Compare&, const _Key&, const _Key&>,
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~