Submission #624053

#TimeUsernameProblemLanguageResultExecution timeMemory
624053ArnchSplit the sequence (APIO14_sequence)C++17
Compilation error
0 ms0 KiB
// oooo /* har chi delet mikhad bebar ~ gitar o ba khodet nabar! ~ ;Amoo_Hasan; */ #include<bits/stdc++.h> #pragma GCC optimize("O3,no-stack-protector,unroll-loops") //#pragma GCC target("avx2,fma") using namespace std; typedef long long ll; typedef long double ld; #define Sz(x) int((x).size()) #define All(x) (x).begin(), (x).end() #define wtf(x) cout<<#x <<" : " <<x <<endl #define mak make_pair constexpr ll INF = 1e18, N = 1e5 + 10, MAXK = 2e2 + 10; int n, k; ll a[N], ps[N], dp[N][MAXK]; pair<ll, ll> par[N][MAXK]; bool mark[N]; ll cost(ll l, ll r) { return (ps[r] - ps[max(0, l - 1)]) * (ps[r] - ps[max(0, l - 1)]); } void Solve(int j, int l = 1, int r = n, int le = 1, int ri = n) { if(l > r) return; ll mid = (l + r) >> 1, opt = -1, best = INF; for(int i = max(0, le); i <= min(mid, 1ll * ri); i++) { if(dp[i - 1][j - 1] == -1) continue; ll cur = dp[i - 1][j - 1] + cost(i, mid); if(best >= cur) { best = cur; opt = i; } } if(best == INF) dp[mid][j] = -1; else { dp[mid][j] = best; par[mid][j] = mak(opt - 1, j - 1); } Solve(j, l, mid - 1, le, opt), Solve(j, mid + 1, r, opt, ri); } int main() { ios :: sync_with_stdio(0), cin.tie(0); cin >>n >>k; for(int i = 1; i <= n; i++) cin >>a[i]; for(int i = 1; i <= n; i++) ps[i] = ps[i - 1] + a[i]; /* for(int i = 0; i <= n; i++) for(int j = 0; j <= k + 1; j++) dp[i][j] = INF; */ for(int j = 1; j <= k + 1; j++) dp[0][j] = -1; dp[0][0] = 0; for(int j = 1; j <= k + 1; j++) { Solve(j); } ll ans = ps[n] * ps[n]; ans -= dp[n][k + 1]; ans /= 2; cout<<ans <<endl; vector<int> pos; pair<ll, ll> p = mak(n, k + 1); while(p.second > 0) { p = par[p.first][p.second]; if(p.first > 0) pos.push_back(p.first); } while(!pos.empty()) { cout<<pos.back() <<" "; pos.pop_back(); } return 0; }

Compilation message (stderr)

sequence.cpp: In function 'll cost(ll, ll)':
sequence.cpp:30:33: error: no matching function for call to 'max(int, ll)'
   30 |  return (ps[r] - ps[max(0, l - 1)]) * (ps[r] - ps[max(0, l - 1)]);
      |                                 ^
In file included 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 sequence.cpp:8:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
sequence.cpp:30:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   30 |  return (ps[r] - ps[max(0, l - 1)]) * (ps[r] - ps[max(0, l - 1)]);
      |                                 ^
In file included 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 sequence.cpp:8:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
sequence.cpp:30:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   30 |  return (ps[r] - ps[max(0, l - 1)]) * (ps[r] - ps[max(0, l - 1)]);
      |                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sequence.cpp:8:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
sequence.cpp:30:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   30 |  return (ps[r] - ps[max(0, l - 1)]) * (ps[r] - ps[max(0, l - 1)]);
      |                                 ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sequence.cpp:8:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
sequence.cpp:30:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   30 |  return (ps[r] - ps[max(0, l - 1)]) * (ps[r] - ps[max(0, l - 1)]);
      |                                 ^
sequence.cpp:30:63: error: no matching function for call to 'max(int, ll)'
   30 |  return (ps[r] - ps[max(0, l - 1)]) * (ps[r] - ps[max(0, l - 1)]);
      |                                                               ^
In file included 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 sequence.cpp:8:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
sequence.cpp:30:63: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   30 |  return (ps[r] - ps[max(0, l - 1)]) * (ps[r] - ps[max(0, l - 1)]);
      |                                                               ^
In file included 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 sequence.cpp:8:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
sequence.cpp:30:63: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   30 |  return (ps[r] - ps[max(0, l - 1)]) * (ps[r] - ps[max(0, l - 1)]);
      |                                                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sequence.cpp:8:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
sequence.cpp:30:63: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   30 |  return (ps[r] - ps[max(0, l - 1)]) * (ps[r] - ps[max(0, l - 1)]);
      |                                                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sequence.cpp:8:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
sequence.cpp:30:63: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   30 |  return (ps[r] - ps[max(0, l - 1)]) * (ps[r] - ps[max(0, l - 1)]);
      |                                                               ^