Submission #1310343

#TimeUsernameProblemLanguageResultExecution timeMemory
1310343AliMark71Longest Trip (IOI23_longesttrip)C++20
Compilation error
0 ms0 KiB
#include "longesttrip.h" #include <bits/stdc++.h> template<typename T> using vec = std::vector<T>; using namespace std; std::vector<int> longest_trip(int N, int D) { vec<int> nodes(N); for (int i = 0; i < N; i++) nodes[i] = i; if (D == 3) return nodes; if (D == 2) { deque<int> path{0, are_connected({0}, {1}) ? 1 : 2}; nodes.erase(find(nodes.begin(), nodes.end(), path.front())); nodes.erase(find(nodes.begin(), nodes.end(), path.back())); while (!nodes.empty()) { auto u = nodes.back(); nodes.pop_back(); if (are_connected({path.front()}, {u})) path.push_front(u); else path.push_back(u); } return vec<int>(path.begin(), path.end()); } list<int> path[2] = {{0}, {1}}; nodes.erase(find(nodes.begin(), nodes.end(), path[0].back())); nodes.erase(find(nodes.begin(), nodes.end(), path[1].back())); while (!nodes.empty()) { auto u = nodes.back(); nodes.pop_back(); if (are_connected({path[0].back()}, {u})) path[0].push_back(u); else if (are_connected({path[1].back()}, {u})) path[1].push_back(u); else { path[1].reverse(); path[0].splice(path[0].end(), path[1]); path[1] = {u}; } } return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end()); }

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:47:80: error: class template argument deduction failed:
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
longesttrip.cpp:47:80: error: no matching function for call to 'vector(std::__cxx11::list<int>::iterator, std::__cxx11::list<int>::iterator)'
In file included from /usr/include/c++/13/vector:66,
                 from longesttrip.h:1,
                 from longesttrip.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:2023:5: note: candidate: 'template<class T, class _InputIterator, class, class> std::vector(_InputIterator, _InputIterator, allocator<_Up>)-> vector<_Tp>'
 2023 |     vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
      |     ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:2023:5: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:80: note:   couldn't deduce template parameter 'T'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
/usr/include/c++/13/bits/stl_vector.h:428:11: note: candidate: 'template<class T> vector(std::vector<_Tp>)-> std::vector<_Tp>'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:428:11: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:80: note:   'std::_List_iterator<int>' is not derived from 'std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
/usr/include/c++/13/bits/stl_vector.h:531:7: note: candidate: 'template<class T> vector()-> std::vector<_Tp>'
  531 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:531:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:80: note:   candidate expects 0 arguments, 2 provided
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
/usr/include/c++/13/bits/stl_vector.h:542:7: note: candidate: 'template<class T> vector(const std::allocator<_Up>&)-> std::vector<_Tp>'
  542 |       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:542:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:80: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::allocator<_Up>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
/usr/include/c++/13/bits/stl_vector.h:556:7: note: candidate: 'template<class T> vector(std::size_t, const std::allocator<_Up>&)-> std::vector<_Tp>'
  556 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:556:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:80: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::allocator<_Up>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
/usr/include/c++/13/bits/stl_vector.h:569:7: note: candidate: 'template<class T> vector(std::size_t, const _Tp&, const std::allocator<_Up>&)-> std::vector<_Tp>'
  569 |       vector(size_type __n, const value_type& __value,
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:569:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:63: note:   cannot convert 'path[0].std::__cxx11::list<int>::begin()' (type 'std::__cxx11::list<int>::iterator') to type 'std::size_t' {aka 'long unsigned int'}
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                  ~~~~~~~~~~~~~^~
/usr/include/c++/13/bits/stl_vector.h:601:7: note: candidate: 'template<class T> vector(const std::vector<_Tp>&)-> std::vector<_Tp>'
  601 |       vector(const vector& __x)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:601:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:80: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
/usr/include/c++/13/bits/stl_vector.h:620:7: note: candidate: 'template<class T> vector(std::vector<_Tp>&&)-> std::vector<_Tp>'
  620 |       vector(vector&&) noexcept = default;
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:620:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:80: note:   'std::__cxx11::list<int>::iterator' is not derived from 'std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
/usr/include/c++/13/bits/stl_vector.h:624:7: note: candidate: 'template<class T> vector(const std::vector<_Tp>&, std::__type_identity_t<std::allocator<_Up> >&)-> std::vector<_Tp>'
  624 |       vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:624:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:80: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
/usr/include/c++/13/bits/stl_vector.h:635:7: note: candidate: 'template<class T> vector(std::vector<_Tp>&&, const std::allocator<_Up>&, std::true_type)-> std::vector<_Tp>'
  635 |       vector(vector&& __rv, const allocator_type& __m, true_type) noexcept
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:635:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:80: note:   'std::__cxx11::list<int>::iterator' is not derived from 'std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
/usr/include/c++/13/bits/stl_vector.h:640:7: note: candidate: 'template<class T> vector(std::vector<_Tp>&&, const std::allocator<_Up>&, std::false_type)-> std::vector<_Tp>'
  640 |       vector(vector&& __rv, const allocator_type& __m, false_type)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:640:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:80: note:   'std::__cxx11::list<int>::iterator' is not derived from 'std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
/usr/include/c++/13/bits/stl_vector.h:659:7: note: candidate: 'template<class T> vector(std::vector<_Tp>&&, std::__type_identity_t<std::allocator<_Up> >&)-> std::vector<_Tp>'
  659 |       vector(vector&& __rv, const __type_identity_t<allocator_type>& __m)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:659:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:80: note:   'std::__cxx11::list<int>::iterator' is not derived from 'std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
/usr/include/c++/13/bits/stl_vector.h:678:7: note: candidate: 'template<class T> vector(std::initializer_list<_Tp>, const std::allocator<_Up>&)-> std::vector<_Tp>'
  678 |       vector(initializer_list<value_type> __l,
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:678:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:80: note:   'std::_List_iterator<int>' is not derived from 'std::initializer_list<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
/usr/include/c++/13/bits/stl_vector.h:707:9: note: candidate: 'template<class T, class _InputIterator, class> vector(_InputIterator, _InputIterator, const std::allocator<_Up>&)-> std::vector<_Tp>'
  707 |         vector(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:707:9: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:80: note:   couldn't deduce template parameter 'T'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                ^
longesttrip.cpp:47:118: error: class template argument deduction failed:
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^
longesttrip.cpp:47:118: error: no matching function for call to 'vector(std::__cxx11::list<int>::iterator, std::__cxx11::list<int>::iterator)'
/usr/include/c++/13/bits/stl_vector.h:2023:5: note: candidate: 'template<class T, class _InputIterator, class, class> std::vector(_InputIterator, _InputIterator, allocator<_Up>)-> vector<_Tp>'
 2023 |     vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
      |     ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:2023:5: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:118: note:   couldn't deduce template parameter 'T'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^
/usr/include/c++/13/bits/stl_vector.h:428:11: note: candidate: 'template<class T> vector(std::vector<_Tp>)-> std::vector<_Tp>'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:428:11: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:118: note:   'std::_List_iterator<int>' is not derived from 'std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^
/usr/include/c++/13/bits/stl_vector.h:531:7: note: candidate: 'template<class T> vector()-> std::vector<_Tp>'
  531 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:531:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:118: note:   candidate expects 0 arguments, 2 provided
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^
/usr/include/c++/13/bits/stl_vector.h:542:7: note: candidate: 'template<class T> vector(const std::allocator<_Up>&)-> std::vector<_Tp>'
  542 |       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:542:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:118: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::allocator<_Up>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^
/usr/include/c++/13/bits/stl_vector.h:556:7: note: candidate: 'template<class T> vector(std::size_t, const std::allocator<_Up>&)-> std::vector<_Tp>'
  556 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:556:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:118: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::allocator<_Up>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^
/usr/include/c++/13/bits/stl_vector.h:569:7: note: candidate: 'template<class T> vector(std::size_t, const _Tp&, const std::allocator<_Up>&)-> std::vector<_Tp>'
  569 |       vector(size_type __n, const value_type& __value,
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:569:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:101: note:   cannot convert 'path[1].std::__cxx11::list<int>::begin()' (type 'std::__cxx11::list<int>::iterator') to type 'std::size_t' {aka 'long unsigned int'}
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                        ~~~~~~~~~~~~~^~
/usr/include/c++/13/bits/stl_vector.h:601:7: note: candidate: 'template<class T> vector(const std::vector<_Tp>&)-> std::vector<_Tp>'
  601 |       vector(const vector& __x)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:601:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:118: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^
/usr/include/c++/13/bits/stl_vector.h:620:7: note: candidate: 'template<class T> vector(std::vector<_Tp>&&)-> std::vector<_Tp>'
  620 |       vector(vector&&) noexcept = default;
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:620:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:118: note:   'std::__cxx11::list<int>::iterator' is not derived from 'std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^
/usr/include/c++/13/bits/stl_vector.h:624:7: note: candidate: 'template<class T> vector(const std::vector<_Tp>&, std::__type_identity_t<std::allocator<_Up> >&)-> std::vector<_Tp>'
  624 |       vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:624:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:118: note:   'std::__cxx11::list<int>::iterator' is not derived from 'const std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^
/usr/include/c++/13/bits/stl_vector.h:635:7: note: candidate: 'template<class T> vector(std::vector<_Tp>&&, const std::allocator<_Up>&, std::true_type)-> std::vector<_Tp>'
  635 |       vector(vector&& __rv, const allocator_type& __m, true_type) noexcept
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:635:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:118: note:   'std::__cxx11::list<int>::iterator' is not derived from 'std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^
/usr/include/c++/13/bits/stl_vector.h:640:7: note: candidate: 'template<class T> vector(std::vector<_Tp>&&, const std::allocator<_Up>&, std::false_type)-> std::vector<_Tp>'
  640 |       vector(vector&& __rv, const allocator_type& __m, false_type)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:640:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:118: note:   'std::__cxx11::list<int>::iterator' is not derived from 'std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^
/usr/include/c++/13/bits/stl_vector.h:659:7: note: candidate: 'template<class T> vector(std::vector<_Tp>&&, std::__type_identity_t<std::allocator<_Up> >&)-> std::vector<_Tp>'
  659 |       vector(vector&& __rv, const __type_identity_t<allocator_type>& __m)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:659:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:118: note:   'std::__cxx11::list<int>::iterator' is not derived from 'std::vector<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^
/usr/include/c++/13/bits/stl_vector.h:678:7: note: candidate: 'template<class T> vector(std::initializer_list<_Tp>, const std::allocator<_Up>&)-> std::vector<_Tp>'
  678 |       vector(initializer_list<value_type> __l,
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:678:7: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:118: note:   'std::_List_iterator<int>' is not derived from 'std::initializer_list<_Tp>'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^
/usr/include/c++/13/bits/stl_vector.h:707:9: note: candidate: 'template<class T, class _InputIterator, class> vector(_InputIterator, _InputIterator, const std::allocator<_Up>&)-> std::vector<_Tp>'
  707 |         vector(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:707:9: note:   template argument deduction/substitution failed:
longesttrip.cpp:47:118: note:   couldn't deduce template parameter 'T'
   47 |     return path[0].size() > path[1].size() ? vec(path[0].begin(), path[1].end()) : vec(path[1].begin(), path[1].end());
      |                                                                                                                      ^