Submission #127949

#TimeUsernameProblemLanguageResultExecution timeMemory
127949SortingBoxes with souvenirs (IOI15_boxes)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e7 + 7; vector<long long> v1, v2; vector<long long> v3, v4; void output(vector<long long> v){ for(long long &x: v){ cout << x << " "; } cout << endl; } long long delivery(int n, int k, int l, int *positions){ sort(positions, positions + n); int idx = 0; for(; idx < n && positions[idx] <= l / 2; idx++){ v1.push_back(positions[idx]); } for(; idx < n; idx++){ v2.push_back(l - positions[idx]); } if(!v2.empty()){ reverse(v2.begin(), v2.end()); } //output(v1); //output(v2); long long ans = 0, sum1 = 0, sum2 = 0; for(int i = -1; true;){ if(i + k >= (int)v1.size()){ for(++i; i < (int)v1.size(); ++i){ v3.push_back(v1[i]); } break; } i += k; sum1 += (long long)v1[i] * 2ll; } for(int i = -1; true;){ if(i + k >= (int)v2.size()){ for(++i; i < (int)v2.size(); ++i){ v4.push_back(v2[i]); } break; } i += k; sum2 += (long long)v2[i] * 2ll; } //output(v3); //output(v4); ans = sum1 + sum2; if(v3.empty() || v4.empty()){ if(!v3.empty()){ ans += v3.back() * 2ll; } if(!v4.empty()){ ans += v4.back() * 2ll; } return ans; } if((int)v3.size() + (int)v4.size() <= k){ ans += min(l, v3.back() * 2ll + v4.back() * 2ll); return ans; } int j = (int)v3.size() + (int)v4.size() - k; ans += v3.back() * 2ll + v4.back() * 2ll; if((int)v3.size() >= j){ long long ans2 = sum2; for(int i = (int)v1.size() + j - (int)v3.size() - 1; i >= 0; i -= k){ ans2 += 2ll * v1[i]; } ans = min(ans, ans2); } if((int)v4.size() >= j){ long long ans2 = sum2; for(int i = (int)v2.size() + j - (int)v4.size() - 1; i >= 0; i -= k){ ans2 += 2ll * v2[i]; } ans = min(ans, ans2); } return ans; } /*int positions[N], n, k, l; int main(){ cin >> n >> k >> l; for(int i = 0; i < n; i++){ cin >> positions[i]; } cout << delivery(n, k, l, positions) << "\n"; return 0; }*/ /* 3 2 8 1 2 5 */

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:75:50: error: no matching function for call to 'min(int&, __gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type)'
   ans += min(l, v3.back() * 2ll + v4.back() * 2ll);
                                                  ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from boxes.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
boxes.cpp:75:50: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type {aka long long int}')
   ans += min(l, v3.back() * 2ll + v4.back() * 2ll);
                                                  ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from boxes.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
boxes.cpp:75:50: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type {aka long long int}')
   ans += min(l, v3.back() * 2ll + v4.back() * 2ll);
                                                  ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from boxes.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
boxes.cpp:75:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   ans += min(l, v3.back() * 2ll + v4.back() * 2ll);
                                                  ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from boxes.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
boxes.cpp:75:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   ans += min(l, v3.back() * 2ll + v4.back() * 2ll);
                                                  ^