Submission #1106577

#TimeUsernameProblemLanguageResultExecution timeMemory
1106577salmonFun Tour (APIO20_fun)C++14
Compilation error
0 ms0 KiB
#include "fun.h" #include <bits/stdc++.h> using namespace std; vector<int> createFunTour(int N, int Q){ int lst[N + 1]; int d[N + 1]; int d1[N + 2][2]; set<pair<int,int>,greater<pair<int,int>>> sat[3]; for(int i = 0; i < N; i++){ lst[i] = attractionsBehind(0,i); } pair<int,int> ii = {N + 90,-1}; for(int i = 0; i < N; i++){ if(lst[i] >= (N+1)/2 ) ii = min(ii,{lst[i],i}); } int it = ii.second; for(int i = 0; i < N; i++){ d[i] = hoursRequired(it,i); } vector<int> tee; for(int i = 0; i < N; i++){ if(d[i] == 1) tee.push_back(i); } if(tee.size() == 1){ return {0,1}; } else{ for(int i = 0; i < N; i++){ d1[i][0] = hoursRequired(i,tee[0]); d1[i][1] = hoursRequired(i,tee[1]); } for(int i = 0; i < N; i++){ if(i == it) continue; if(d1[i][0] < d[i]){ sat[0].insert({d[i],i}); } else if(d1[i][1] < d[i]){ sat[1].insert({d[i],i}); } else sat[2].insert(i); } int prev = -1; vector<int> ans = {}; while(max(max(sat[0].size(),sat[1].size() ), sat[2].size()) < (N/2) ){ if(prev == -1){ pair<int,int> ii = {-10,-1}; for(int i = 0; i < 3; i++) ii = max(ii, {sat[i].begin() -> first,i}); prev = ii.second; ans.push_back(sat[prev].begin() -> second); sat[prev].erase(sat[prev].begin()); N--; } else{ pair<int,int> ii = {-10,-1}; for(int i = 0; i < 3; i++) if(i != prev) ii = max(ii, {sat[i].begin() -> first,i}); prev = ii.second; ans.push_back(sat[prev].begin() -> second); sat[prev].erase(sat[prev].begin()); N--; } } pair<int,int> ii = {-10,-1}; for(int i = 0; i < 3; i++) ii = max(ii, {sat[i].size(),i}); int fat = ii.second; while(sat[0].size() + sat[1].size() + sat[2].size() > 0){ if(prev != fat){ prev = fat; ans.push_back(sat[prev].begin() -> second); sat[prev].erase(sat[prev].begin()); N-- } else{ for(int i = 0; i < 3; i++) if(i != prev && !sat[i].empty())ii = max(ii, {sat[i].begin() -> first,i}); prev = ii.second; ans.push_back(sat[prev].begin() -> second); sat[prev].erase(sat[prev].begin()); N--; } } ans.push_back(it); return ans; } }

Compilation message (stderr)

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:50:33: error: no matching function for call to 'std::set<std::pair<int, int>, std::greater<std::pair<int, int> > >::insert(int&)'
   50 |             else sat[2].insert(i);
      |                                 ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from fun.cpp:2:
/usr/include/c++/10/bits/stl_set.h:509:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = std::pair<int, int>; _Compare = std::greater<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::greater<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  509 |       insert(const value_type& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:509:32: note:   no known conversion for argument 1 from 'int' to 'const value_type&' {aka 'const std::pair<int, int>&'}
  509 |       insert(const value_type& __x)
      |              ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:518:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::greater<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::greater<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  518 |       insert(value_type&& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:518:27: note:   no known conversion for argument 1 from 'int' to 'std::set<std::pair<int, int>, std::greater<std::pair<int, int> > >::value_type&&' {aka 'std::pair<int, int>&&'}
  518 |       insert(value_type&& __x)
      |              ~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_set.h:546:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = std::pair<int, int>; _Compare = std::greater<std::pair<int, int> >; _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> >, std::greater<std::pair<int, int> >, 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> >, std::greater<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  546 |       insert(const_iterator __position, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:546:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/10/bits/stl_set.h:551:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::greater<std::pair<int, int> >; _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> >, std::greater<std::pair<int, int> >, 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> >, std::greater<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  551 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:551:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/10/bits/stl_set.h:566:2: note: candidate: 'template<class _InputIterator> void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::pair<int, int>; _Compare = std::greater<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
  566 |  insert(_InputIterator __first, _InputIterator __last)
      |  ^~~~~~
/usr/include/c++/10/bits/stl_set.h:566:2: note:   template argument deduction/substitution failed:
fun.cpp:50:33: note:   candidate expects 2 arguments, 1 provided
   50 |             else sat[2].insert(i);
      |                                 ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from fun.cpp:2:
/usr/include/c++/10/bits/stl_set.h:578:7: note: candidate: 'void std::set<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = std::pair<int, int>; _Compare = std::greater<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
  578 |       insert(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:578:43: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<std::pair<int, int> >'
  578 |       insert(initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
fun.cpp:57:69: warning: comparison of integer expressions of different signedness: 'const long unsigned int' and 'int' [-Wsign-compare]
   57 |         while(max(max(sat[0].size(),sat[1].size() ), sat[2].size()) < (N/2) ){
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
fun.cpp:88:20: error: expected ';' before '}' token
   88 |                 N--
      |                    ^
      |                    ;
   89 |             }
      |             ~