Submission #1239831

#TimeUsernameProblemLanguageResultExecution timeMemory
1239831arvxsBoxes with souvenirs (IOI15_boxes)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;


long long delivery(int N, int K, int L, int positions[]) {

	vector<int> left(N), right(N);


	for (int i = 0; i < N; i++) {
		left[i] = positions[i];
		if (positions[i] < L / 2) {
			left[i] += positions[i];
		} else {
			left[i] = L;
		}

		if (i + 1 > K) {
			left[i] += left[i - K];
		}
	}

	for (int i = N - 1; i >= 0; i--) {
		right[i] = L - positions[i];

		if (L <= positions[i] + L / 2) {
			right += (L - positions[i]);
		} else {
			right[i] = L;
		}

		if (N - i > K) {
			right[i] += right[i + K];
		}
	}

	long long ans = min(left[N - 1], right[0]);

	for (int i = 1; i < N - 1; i++) {
		ans = min(ans, left[i] + right[i + 1]);
	}

	return ans;

}

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:28:31: error: no match for 'operator+=' (operand types are 'std::vector<int>' and 'int')
   28 |                         right += (L - positions[i]);
      |                         ~~~~~~^~~~~~~~~~~~~~~~~~~~~
boxes.cpp:41:26: error: no matching function for call to 'min(long long int&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type)'
   41 |                 ans = min(ans, left[i] + right[i + 1]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from boxes.cpp:1:
/usr/include/c++/11/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++/11/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
boxes.cpp:41:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   41 |                 ans = min(ans, left[i] + right[i + 1]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from boxes.cpp:1:
/usr/include/c++/11/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++/11/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
boxes.cpp:41:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   41 |                 ans = min(ans, left[i] + right[i + 1]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from boxes.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3449:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3449 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3449:5: note:   template argument deduction/substitution failed:
boxes.cpp:41:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   41 |                 ans = min(ans, left[i] + right[i + 1]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from boxes.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3455:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3455 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3455:5: note:   template argument deduction/substitution failed:
boxes.cpp:41:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   41 |                 ans = min(ans, left[i] + right[i + 1]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~