Submission #979663

# Submission time Handle Problem Language Result Execution time Memory
979663 2024-05-11T09:36:10 Z canadavid1 A Plus B (IOI23_aplusb) C++17
Compilation error
0 ms 0 KB
#include "aplusb.h"
#include <set>
#include <utility>
std::vector<int> smallest_sums(int N, std::vector<int> A, std::vector<int> B) {
  	auto cmp = [&](auto a,auto b){return A[a.first]+B[a.second]<A[b.first]+B[b.second];};
	std::set<std::pair<int,int>,decltype(cmp)> q(cmp);
  	std::vector<int> out;
  	q.emplace(0,0);
  	while(out.size()<N)
    {
      auto[a,b] = *q.begin();
      out.push_back(A[a]+B[b]);
      q.erase(out.begin());
      if(a+1<N) q.emplace(a+1,b);
      if(b+1<N) q.emplace(a,b+1);
    }
  	return out;
}

Compilation message

aplusb.cpp: In function 'std::vector<int> smallest_sums(int, std::vector<int>, std::vector<int>)':
aplusb.cpp:9:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    9 |    while(out.size()<N)
      |          ~~~~~~~~~~^~
aplusb.cpp:13:26: error: no matching function for call to 'std::set<std::pair<int, int>, smallest_sums(int, std::vector<int>, std::vector<int>)::<lambda(auto:1, auto:2)> >::erase(std::vector<int>::iterator)'
   13 |       q.erase(out.begin());
      |                          ^
In file included from /usr/include/c++/10/set:61,
                 from aplusb.cpp:2:
/usr/include/c++/10/bits/stl_set.h:654:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(std::set<_Key, _Compare, _Alloc>::const_iterator) [with _Key = std::pair<int, int>; _Compare = smallest_sums(int, std::vector<int>, std::vector<int>)::<lambda(auto:1, auto:2)>; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, smallest_sums(int, std::vector<int>, std::vector<int>)::<lambda(auto:1, auto:2)>, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, smallest_sums(int, std::vector<int>, std::vector<int>)::<lambda(auto:1, auto:2)>, std::allocator<std::pair<int, int> > >::const_iterator]'
  654 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/10/bits/stl_set.h:654:28: note:   no known conversion for argument 1 from 'std::vector<int>::iterator' to 'std::set<std::pair<int, int>, smallest_sums(int, std::vector<int>, std::vector<int>)::<lambda(auto:1, auto:2)> >::const_iterator' {aka 'std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, smallest_sums(int, std::vector<int>, std::vector<int>)::<lambda(auto:1, auto:2)>, std::allocator<std::pair<int, int> > >::const_iterator'}
  654 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:684:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = std::pair<int, int>; _Compare = smallest_sums(int, std::vector<int>, std::vector<int>)::<lambda(auto:1, auto:2)>; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::size_type = long unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = std::pair<int, int>]'
  684 |       erase(const key_type& __x)
      |       ^~~~~
/usr/include/c++/10/bits/stl_set.h:684:29: note:   no known conversion for argument 1 from 'std::vector<int>::iterator' to 'const key_type&' {aka 'const std::pair<int, int>&'}
  684 |       erase(const key_type& __x)
      |             ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:706:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::const_iterator) [with _Key = std::pair<int, int>; _Compare = smallest_sums(int, std::vector<int>, std::vector<int>)::<lambda(auto:1, auto:2)>; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, smallest_sums(int, std::vector<int>, std::vector<int>)::<lambda(auto:1, auto:2)>, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, smallest_sums(int, std::vector<int>, std::vector<int>)::<lambda(auto:1, auto:2)>, std::allocator<std::pair<int, int> > >::const_iterator]'
  706 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/10/bits/stl_set.h:706:7: note:   candidate expects 2 arguments, 1 provided