제출 #567893

#제출 시각아이디문제언어결과실행 시간메모리
567893Trisanu_Das선물상자 (IOI15_boxes)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int delivery(int n, int k, int l, int a){ int dp1[n + 1], dp2[n + 1], pos[n + 1]; dp1[0] = 0; dp2[0] = 0; for(int i = 0; i < n; i++) pos[i + 1] = a[i]; sort(a + 1, a + n + 1); for(int i = 1; i <= n ; i++){ dp1[i] = dp1[max(0, i - k)] + 2 * pos[i]; } for(int i = 1; i <= n ; i++){ dp2[i] = 2 * (l - pos[i]) + dp2[min(n + 1, i + k)]; } int ans = 1e9; for (int i = 1;i < n + 1;i++) ans = min(ans, dp1[i - 1] + dp2[i]); for (int i = k;i <= n;i++) ans = min(ans, dp[i - k] + dp2[i + 1] + l); return ans; }

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

boxes.cpp: In function 'int delivery(int, int, int, int)':
boxes.cpp:6:44: error: invalid types 'int[int]' for array subscript
    6 |   for(int i = 0; i < n; i++) pos[i + 1] = a[i];
      |                                            ^
boxes.cpp:16:45: error: 'dp' was not declared in this scope; did you mean 'dp2'?
   16 |   for (int i = k;i <= n;i++) ans = min(ans, dp[i - k] + dp2[i + 1] + l);
      |                                             ^~
      |                                             dp2
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from boxes.cpp:1:
/usr/include/c++/10/bits/stl_algo.h: In instantiation of 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
/usr/include/c++/10/bits/stl_algo.h:1886:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:1977:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:4859:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = int]'
boxes.cpp:7:24:   required from here
/usr/include/c++/10/bits/stl_algo.h:1849:3: error: no type named 'value_type' in 'struct std::iterator_traits<int>'
 1849 |   __val = _GLIBCXX_MOVE(*__i);
      |   ^~~~~
/usr/include/c++/10/bits/stl_algo.h:1851:8: error: invalid type argument of unary '*' (have 'int')
 1851 |        *__first = _GLIBCXX_MOVE(__val);
      |        ^~~~~~~~
/usr/include/c++/10/bits/stl_algo.h:1849:3: error: no type named 'value_type' in 'struct std::iterator_traits<int>'
 1849 |   __val = _GLIBCXX_MOVE(*__i);
      |   ^~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from boxes.cpp:1:
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = int; _Iterator2 = int]':
/usr/include/c++/10/bits/stl_algo.h:82:17:   required from 'void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:1924:34:   required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:1958:38:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = int; _Size = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:1974:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:4859:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = int]'
boxes.cpp:7:24:   required from here
/usr/include/c++/10/bits/predefined_ops.h:43:16: error: invalid type argument of unary '*' (have 'int')
   43 |       { return *__it1 < *__it2; }
      |                ^~~~~~
/usr/include/c++/10/bits/predefined_ops.h:43:25: error: invalid type argument of unary '*' (have 'int')
   43 |       { return *__it1 < *__it2; }
      |                         ^~~~~~
In file included from /usr/include/c++/10/bits/stl_algo.h:61,
                 from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from boxes.cpp:1:
/usr/include/c++/10/bits/stl_heap.h: In instantiation of 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
/usr/include/c++/10/bits/stl_algo.h:1666:23:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:1937:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:1953:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = int; _Size = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:1974:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:4859:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = int]'
boxes.cpp:7:24:   required from here
/usr/include/c++/10/bits/stl_heap.h:343:4: error: no type named 'value_type' in 'struct std::iterator_traits<int>'
  343 |    _ValueType;
      |    ^~~~~~~~~~
/usr/include/c++/10/bits/stl_heap.h:345:4: error: no type named 'difference_type' in 'struct std::iterator_traits<int>'
  345 |    _DistanceType;
      |    ^~~~~~~~~~~~~
/usr/include/c++/10/bits/stl_heap.h: In instantiation of 'void std::__pop_heap(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
/usr/include/c++/10/bits/stl_algo.h:1669:19:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:1937:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:1953:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = int; _Size = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:1974:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/10/bits/stl_algo.h:4859:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = int]'
boxes.cpp:7:24:   required from here
/usr/include/c++/10/bits/stl_heap.h:257:2: error: no type named 'value_type' in 'struct std::iterator_traits<int>'
  257 |  _ValueType;
      |  ^~~~~~~~~~
/usr/include/c++/10/bits/stl_heap.h:259:2: error: no type named 'difference_type' in 'struct std::iterator_traits<int>'
  259 |  _DistanceType;
      |  ^~~~~~~~~~~~~
/usr/include/c++/10/bits/stl_heap.h:262:7: error: invalid type argument of unary '*' (have 'int')
  262 |       *__result = _GLIBCXX_MOVE(*__first);
      |       ^~~~~~~~~
In file included from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from boxes.cpp:1:
/usr/include/c++/10/bits/stl_heap.h:262:19: error: invalid type argument of unary '*' (have 'int')
  262 |       *__result = _GLIBCXX_MOVE(*__first);
      |                   ^~~~~~~~~~~~~