# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1269442 | rayan_bd | 수열 (APIO14_sequence) | C++20 | 컴파일 에러 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const long long int = -4e18;
struct Line {
mutable int k, m, p, idx;
bool operator<(const Line& o) const { return k < o.k; }
bool operator<(int x) const { return p < x; }
};
struct LineContainer : multiset<Line, less<>> {
static const int inf = LLONG_MAX;
int div(int a, int b) { return a / b - ((a ^ b) < 0 && a % b); }
bool isect(iterator x, iterator y) {
if (y == end()) { x->p = inf; return false; }
if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
else x->p = div(y->m - x->m, x->k - y->k);
return x->p >= y->p;
}
void add(int k, int m, int idx) {
auto z = insert({k, m, 0, idx}), y = z++, x = y;
while (isect(y, z)) z = erase(z);
if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
while ((y = x) != begin() && (--x)->p >= y->p)
isect(x, erase(y));
}
pair<int,int> query(int x) {
assert(!empty());
auto l = *lower_bound(x);
return {l.k * x + l.m, l.idx};
}
};
signed main(){
ios::sync_with_stdio(0);
cin.tie(nullptr);
int n, K;
cin >> n >> K;
vector<int> ar(n + 1), pref(n + 1);
for(int i = 1; i <= n; ++i){
cin >> ar[i];
pref[i] = pref[i - 1] + ar[i];
}
vector<pair<int,int>> dp(n + 2, {inf, -1});
for (int i = 1; i <= n+1; i++) dp[i] = {0, -1};
for (int k = 1; k <= K; k++) {
LineContainer cht;
vector<pair<int,int>> ndp(n + 2, {inf, -1});
for (int j = n; j >= 1; j--) {
int slope = pref[j];
int intercept = dp[j+1].first - pref[j] * pref[j];
cht.add(slope, intercept, j);
int x = pref[n] + pref[j-1];
auto [val, idx] = cht.query(x);
ndp[j] = {-pref[j-1] * pref[n] + val, idx};
}
dp.swap(ndp);
}
cout << dp[1].first << "\n";
int i = 1, k = K;
while (k > 0 && i <= n) {
int j = dp[i].second;
if (j == -1) break;
cout << j << " ";
i = j + 1;
k--;
}
cout << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp:3:13: error: 'long long long' is too long for GCC 3 | #define int long long | ^~~~ sequence.cpp:5:17: note: in expansion of macro 'int' 5 | const long long int = -4e18; | ^~~ sequence.cpp:3:18: error: 'long long long' is too long for GCC 3 | #define int long long | ^~~~ sequence.cpp:5:17: note: in expansion of macro 'int' 5 | const long long int = -4e18; | ^~~ sequence.cpp:5:21: error: expected unqualified-id before '=' token 5 | const long long int = -4e18; | ^ sequence.cpp: In function 'int main()': sequence.cpp:48:38: error: 'inf' was not declared in this scope; did you mean 'ynf'? 48 | vector<pair<int,int>> dp(n + 2, {inf, -1}); | ^~~ | ynf sequence.cpp:48:46: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::vector(long long int, <brace-enclosed initializer list>)' 48 | vector<pair<int,int>> dp(n + 2, {inf, -1}); | ^ In file included from /usr/include/c++/13/vector:66, from /usr/include/c++/13/functional:64, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53, from sequence.cpp:1: /usr/include/c++/13/bits/stl_vector.h:707:9: note: candidate: 'template<class _InputIterator, class> constexpr std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with <template-parameter-2-2> = _InputIterator; _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >]' 707 | vector(_InputIterator __first, _InputIterator __last, | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:707:9: note: template argument deduction/substitution failed: In file included from /usr/include/c++/13/bits/stl_algobase.h:65, from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51: /usr/include/c++/13/bits/stl_iterator_base_types.h: In substitution of 'template<class _InIter> using std::_RequireInputIter = std::__enable_if_t<std::is_convertible<typename std::iterator_traits< <template-parameter-1-1> >::iterator_category, std::input_iterator_tag>::value> [with _InIter = long long int]': /usr/include/c++/13/bits/stl_vector.h:705:9: required from here /usr/include/c++/13/bits/stl_iterator_base_types.h:250:11: error: no type named 'iterator_category' in 'struct std::iterator_traits<long long int>' 250 | using _RequireInputIter = | ^~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_vector.h:678:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; allocator_type = std::allocator<std::pair<long long int, long long int> >]' 678 | vector(initializer_list<value_type> __l, | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:678:43: note: no known conversion for argument 1 from 'long long int' to 'std::initializer_list<std::pair<long long int, long long int> >' 678 | vector(initializer_list<value_type> __l, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/13/bits/stl_vector.h:659:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::__type_identity_t<_Alloc> = std::allocator<std::pair<long long int, long long int> >]' 659 | vector(vector&& __rv, const __type_identity_t<allocator_type>& __m) | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:659:23: note: no known conversion for argument 1 from 'long long int' to 'std::vector<std::pair<long long int, long long int> >&&' 659 | vector(vector&& __rv, const __type_identity_t<allocator_type>& __m) | ~~~~~~~~~^~~~ /usr/include/c++/13/bits/stl_vector.h:640:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::false_type) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; allocator_type = std::allocator<std::pair<long long int, long long int> >; std::false_type = std::integral_constant<bool, false>]' 640 | vector(vector&& __rv, const allocator_type& __m, false_type) | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:640:7: note: candidate expects 3 arguments, 2 provided /usr/include/c++/13/bits/stl_vector.h:635:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::true_type) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; allocator_type = std::allocator<std::pair<long long int, long long int> >; std::true_type = std::integral_constant<bool, true>]' 635 | vector(vector&& __rv, const allocator_type& __m, true_type) noexcept | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:635:7: note: candidate expects 3 arguments, 2 provided /usr/include/c++/13/bits/stl_vector.h:624:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::__type_identity_t<_Alloc> = std::allocator<std::pair<long long int, long long int> >]' 624 | vector(const vector& __x, const __type_identity_t<allocator_type>& __a) | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:624:28: note: no known conversion for argument 1 from 'long long int' to 'const std::vector<std::pair<long long int, long long int> >&' 624 | vector(const vector& __x, const __type_identity_t<allocator_type>& __a) | ~~~~~~~~~~~~~~^~~ /usr/include/c++/13/bits/stl_vector.h:620:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >]' 620 | vector(vector&&) noexcept = default; | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:620:7: note: candidate expects 1 argument, 2 provided /usr/include/c++/13/bits/stl_vector.h:601:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >]' 601 | vector(const vector& __x) | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:601:7: note: candidate expects 1 argument, 2 provided /usr/include/c++/13/bits/stl_vector.h:569:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(size_type, const value_type&, const allocator_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; size_type = long unsigned int; value_type = std::pair<long long int, long long int>; allocator_type = std::allocator<std::pair<long long int, long long int> >]' 569 | vector(size_type __n, const value_type& __value, | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:569:47: note: no known conversion for argument 2 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<long long int, long long int> >::value_type&' {aka 'const std::pair<long long int, long long int>&'} 569 | vector(size_type __n, const value_type& __value, | ~~~~~~~~~~~~~~~~~~^~~~~~~ /usr/include/c++/13/bits/stl_vector.h:556:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; size_type = long unsigned int; allocator_type = std::allocator<std::pair<long long int, long long int> >]' 556 | vector(size_type __n, const allocator_type& __a = allocator_type()) | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:556:51: note: no known conversion for argument 2 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<long long int, long long int> >::allocator_type&' {aka 'const std::allocator<std::pair<long long int, long long int> >&'} 556 | vector(size_type __n, const allocator_type& __a = allocator_type()) | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_vector.h:542:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; allocator_type = std::allocator<std::pair<long long int, long long int> >]' 542 | vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:542:7: note: candidate expects 1 argument, 2 provided /usr/include/c++/13/bits/stl_vector.h:531:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector() [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >]' 531 | vector() = default; | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:531:7: note: candidate expects 0 arguments, 2 provided sequence.cpp:53:51: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::vector(long long int, <brace-enclosed initializer list>)' 53 | vector<pair<int,int>> ndp(n + 2, {inf, -1}); | ^ /usr/include/c++/13/bits/stl_vector.h:707:9: note: candidate: 'template<class _InputIterator, class> constexpr std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with <template-parameter-2-2> = _InputIterator; _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >]' 707 | vector(_InputIterator __first, _InputIterator __last, | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:707:9: note: template argument deduction/substitution failed: /usr/include/c++/13/bits/stl_vector.h:678:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; allocator_type = std::allocator<std::pair<long long int, long long int> >]' 678 | vector(initializer_list<value_type> __l, | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:678:43: note: no known conversion for argument 1 from 'long long int' to 'std::initializer_list<std::pair<long long int, long long int> >' 678 | vector(initializer_list<value_type> __l, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/13/bits/stl_vector.h:659:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::__type_identity_t<_Alloc> = std::allocator<std::pair<long long int, long long int> >]' 659 | vector(vector&& __rv, const __type_identity_t<allocator_type>& __m) | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:659:23: note: no known conversion for argument 1 from 'long long int' to 'std::vector<std::pair<long long int, long long int> >&&' 659 | vector(vector&& __rv, const __type_identity_t<allocator_type>& __m) | ~~~~~~~~~^~~~ /usr/include/c++/13/bits/stl_vector.h:640:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::false_type) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; allocator_type = std::allocator<std::pair<long long int, long long int> >; std::false_type = std::integral_constant<bool, false>]' 640 | vector(vector&& __rv, const allocator_type& __m, false_type) | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:640:7: note: candidate expects 3 arguments, 2 provided /usr/include/c++/13/bits/stl_vector.h:635:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::true_type) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; allocator_type = std::allocator<std::pair<long long int, long long int> >; std::true_type = std::integral_constant<bool, true>]' 635 | vector(vector&& __rv, const allocator_type& __m, true_type) noexcept | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:635:7: note: candidate expects 3 arguments, 2 provided /usr/include/c++/13/bits/stl_vector.h:624:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::__type_identity_t<_Alloc> = std::allocator<std::pair<long long int, long long int> >]' 624 | vector(const vector& __x, const __type_identity_t<allocator_type>& __a) | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:624:28: note: no known conversion for argument 1 from 'long long int' to 'const std::vector<std::pair<long long int, long long int> >&' 624 | vector(const vector& __x, const __type_identity_t<allocator_type>& __a) | ~~~~~~~~~~~~~~^~~ /usr/include/c++/13/bits/stl_vector.h:620:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >]' 620 | vector(vector&&) noexcept = default; | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:620:7: note: candidate expects 1 argument, 2 provided /usr/include/c++/13/bits/stl_vector.h:601:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >]' 601 | vector(const vector& __x) | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:601:7: note: candidate expects 1 argument, 2 provided /usr/include/c++/13/bits/stl_vector.h:569:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(size_type, const value_type&, const allocator_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; size_type = long unsigned int; value_type = std::pair<long long int, long long int>; allocator_type = std::allocator<std::pair<long long int, long long int> >]' 569 | vector(size_type __n, const value_type& __value, | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:569:47: note: no known conversion for argument 2 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<long long int, long long int> >::value_type&' {aka 'const std::pair<long long int, long long int>&'} 569 | vector(size_type __n, const value_type& __value, | ~~~~~~~~~~~~~~~~~~^~~~~~~ /usr/include/c++/13/bits/stl_vector.h:556:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; size_type = long unsigned int; allocator_type = std::allocator<std::pair<long long int, long long int> >]' 556 | vector(size_type __n, const allocator_type& __a = allocator_type()) | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:556:51: note: no known conversion for argument 2 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<long long int, long long int> >::allocator_type&' {aka 'const std::allocator<std::pair<long long int, long long int> >&'} 556 | vector(size_type __n, const allocator_type& __a = allocator_type()) | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_vector.h:542:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; allocator_type = std::allocator<std::pair<long long int, long long int> >]' 542 | vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:542:7: note: candidate expects 1 argument, 2 provided /usr/include/c++/13/bits/stl_vector.h:531:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::vector() [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >]' 531 | vector() = default; | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:531:7: note: candidate expects 0 arguments, 2 provided