제출 #521001

#제출 시각아이디문제언어결과실행 시간메모리
521001szekelymilan선물상자 (IOI15_boxes)C++14
컴파일 에러
0 ms0 KiB
#include <iostream> #include <algorithm> #include <vector> #include "boxes.h" long long delivery(int N, int K, int L, int p[]) { if (K == 1) { long long ans = 0; for (int i = 0; i < N; i++) ans += 2 * std::min(p[i], L - p[i]); return ans; } std::vector<int> v(N); for (int i = 0; i < N; i++) v[i] = p[i]; std::sort(v.begin(), v.end()); long long ans = std::min(v[N - 1], (v[N - 1] == 0 ? 0 : L - *std::upper_bound(v.begin(), v.end(), 0))); for (int i = 0; i < N - 1; i++) ans = std::min(ans, (v[i] == v[N - 1] ? v[i] : 2 * v[i] + 2 * L - *std::upper_bound(v.begin(), v.end(), v[i]))); return ans; }

컴파일 시 표준 에러 (stderr) 메시지

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:20:115: error: no matching function for call to 'min(long long int&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type)'
   20 |     ans = std::min(ans, (v[i] == v[N - 1] ? v[i] : 2 * v[i] + 2 * L - *std::upper_bound(v.begin(), v.end(), v[i])));
      |                                                                                                                   ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from boxes.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
boxes.cpp:20:115: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   20 |     ans = std::min(ans, (v[i] == v[N - 1] ? v[i] : 2 * v[i] + 2 * L - *std::upper_bound(v.begin(), v.end(), v[i])));
      |                                                                                                                   ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from boxes.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
boxes.cpp:20:115: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   20 |     ans = std::min(ans, (v[i] == v[N - 1] ? v[i] : 2 * v[i] + 2 * L - *std::upper_bound(v.begin(), v.end(), v[i])));
      |                                                                                                                   ^
In file included from /usr/include/c++/10/algorithm:62,
                 from boxes.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
boxes.cpp:20:115: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   20 |     ans = std::min(ans, (v[i] == v[N - 1] ? v[i] : 2 * v[i] + 2 * L - *std::upper_bound(v.begin(), v.end(), v[i])));
      |                                                                                                                   ^
In file included from /usr/include/c++/10/algorithm:62,
                 from boxes.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
boxes.cpp:20:115: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   20 |     ans = std::min(ans, (v[i] == v[N - 1] ? v[i] : 2 * v[i] + 2 * L - *std::upper_bound(v.begin(), v.end(), v[i])));
      |                                                                                                                   ^