Submission #1187081

#TimeUsernameProblemLanguageResultExecution timeMemory
1187081harvsftw로봇 (IOI13_robots)C++20
Compilation error
0 ms0 KiB
#pragma GCC optimize("O3,inline")
#include <bits/stdc++.h>
#include "robots.h"
using namespace std;

#define F(i, n) for(int i = 0; i < (n); i++)

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    using state = tuple<int, int, int>;
    
    sort(X, X + A);
    sort(Y, Y + B);

    vector<state> by_weight;
    F(i, T) {
        by_weight.emplace(W[i], S[i], i);
    }
    sort(by_weight.begin(), by_weight.end());

    auto solver = [&](int num_per_robot) {
        priority_queue<pair<int, int>> pq;
    
        auto it = by_weight.begin();
        F(i, A) {
            int robot_weight_limit = X[i];
            while(it != by_weight.end() && get<0>(*it) < robot_weight_limit) {
                pq.emplace(get<1>(*it), get<2>(*it));
                ++it;
            }

            int cnt = num_per_robot;
            while(!pq.empty() && cnt > 0) {
                pq.pop();
                cnt--;
            }
        }

        priority_queue<int> by_size;
        while(!pq.empty()) {
            pq.pop();
            by_size.emplace(-S[idx]);
        }
        while(it != by_weight.end()) {
            by_size.emplace(-get<1>(*it));
            ++it;
        }

        F(i, B) {
            int robot_size_limit = Y[i];
            int cnt = num_per_robot;
            while(by_size.size() && -by_size.top() < robot_size_limit && cnt > 0) {
                by_size.pop();
                cnt--;
            }
        }

        return by_size.empty();
    };

    int l = 1, r = T;
    while(l <= r) {
        int m = (l + r) / 2;
        if(solver(m)) {
            r = m - 1;
        } else {
            l = m + 1;
        }
    }
    
    if(!solver(l)) {
        return -1;
    }
    return l;
};

Compilation message (stderr)

robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:16:26: error: no matching function for call to 'std::vector<std::tuple<int, int, int> >::emplace(int&, int&, int&)'
   16 |         by_weight.emplace(W[i], S[i], i);
      |         ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
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 robots.cpp:2:
/usr/include/c++/11/bits/stl_vector.h:1248:9: note: candidate: 'template<class ... _Args> std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::emplace(std::vector<_Tp, _Alloc>::const_iterator, _Args&& ...) [with _Args = {_Args ...}; _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >]'
 1248 |         emplace(const_iterator __position, _Args&&... __args)
      |         ^~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1248:9: note:   template argument deduction/substitution failed:
robots.cpp:16:30: note:   cannot convert '*(W + ((sizetype)(((long unsigned int)i) * 4)))' (type 'int') to type 'std::vector<std::tuple<int, int, int> >::const_iterator'
   16 |         by_weight.emplace(W[i], S[i], i);
      |                           ~~~^
robots.cpp: In lambda function:
robots.cpp:41:32: error: 'idx' was not declared in this scope
   41 |             by_size.emplace(-S[idx]);
      |                                ^~~