Submission #238040

#TimeUsernameProblemLanguageResultExecution timeMemory
238040DS007Split the sequence (APIO14_sequence)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define evaluate(pt, x) (pt.first.first * x + pt.first.second) const int N = 1e5, K = 205; int a[N], s[N], p[K], n, k, dp[N][K], last[N][K]; vector<pair<pair<int, int>, int>> hull[K]; int find(int i, int j, int x) { p[j] = min(p[j], hull[j].size() - 1ll); for (; p[j] < (int)hull[j].size() - 1; p[j]++) { if (evaluate(hull[j][p[j]], x) > evaluate(hull[j][p[j] + 1], x)) break; } last[i][j + 1] = hull[j][p[j]].second; return evaluate(hull[j][p[j]], x); } bool inter(pair<int, int> a, pair<int, int> b, pair<int, int> c) { return (a.second - b.second) * (c.first - a.first) > (a.second - c.second) * (b.first - a.first); } void insert(int j, pair<pair<int, int>, int> nl) { while (hull[j].size() > 1) { auto temp = hull[j].back(); hull[j].pop_back(); if (inter(nl.first, temp.first, hull[j].back().first)) { hull[j].push_back(temp); break; } } hull[j].push_back(nl); } int solveTestCase() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; s[0] = a[0]; for (int i = 1; i < n; i++) s[i] = s[i - 1] + a[i]; hull[0].push_back({{a[0], -a[0] * a[0]}, 0}); for (int i = 1; i < n; i++) { for (int j = 1; j <= k && j <= i; j++) { dp[i][j] = find(i, j - 1, s[i]); insert(j - 1, {{s[i], dp[i][j - 1] - s[i] * s[i]}, i}); } insert(min(i, k), {{s[i], dp[i][min(i, k)] - s[i] * s[i]}, i}); } cout << dp[n - 1][k] << "\n"; for (int i = last[n - 1][k], j = k; j > 0; --j, i = last[i][j]) cout << i + 1 << " "; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int test = 1; // cin >> test; while (test--) solveTestCase(); }

Compilation message (stderr)

sequence.cpp: In function 'long long int find(long long int, long long int, long long int)':
sequence.cpp:11:42: error: no matching function for call to 'min(long long int&, long long unsigned int)'
     p[j] = min(p[j], hull[j].size() - 1ll);
                                          ^
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 sequence.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:
sequence.cpp:11:42: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
     p[j] = min(p[j], hull[j].size() - 1ll);
                                          ^
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 sequence.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:
sequence.cpp:11:42: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
     p[j] = min(p[j], hull[j].size() - 1ll);
                                          ^
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 sequence.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:
sequence.cpp:11:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
     p[j] = min(p[j], hull[j].size() - 1ll);
                                          ^
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 sequence.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:
sequence.cpp:11:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
     p[j] = min(p[j], hull[j].size() - 1ll);
                                          ^
sequence.cpp: In function 'long long int solveTestCase()':
sequence.cpp:55:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^