Submission #959881

# Submission time Handle Problem Language Result Execution time Memory
959881 2024-04-09T09:18:42 Z mannshah1211 Split the sequence (APIO14_sequence) C++17
Compilation error
0 ms 0 KB
/**
 *  author: hashman
 *  created: 
**/

#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
   if (!first) {
    res += ", ";
   }
   first = false;
   res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() {
  cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__);

const int64_t inf = 1e17;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> p(n + 1);
  for (int i = 1; i <= n; i++) {
    p[i] = p[i - 1] + a[i];
  }
  auto cost = [&](int l, int r) {
    return (1ll * (p[r] - p[l - 1]) * (p[r] - p[l - 1]));
  };
  k++;
  vector<vector<int64_t>> dp(n + 1, vector<int64_t>(k + 1, inf));
  dp[0][0] = 0;
  vector<vector<int>> pr(n + 1, vector<int>(k + 1));
  for (int j = 1; j <= k; j++) {
    for (int i = 1; i <= n; i++) {
      for (int prev = i; prev >= 1; prev--) {
        dp[i][j] = min(dp[i][j], dp[prev - 1][j - 1] + cost(prev, i));
        if (dp[i][j] == dp[prev - 1][j - 1] + cost(prev, i)) {
          pr[i][j] = prev - 1;
        }
      }
    }
  }
  cout << (1ll * p[n] * p[n] - dp[n][k]) / 2 << '\n';
  int cur = n;
  vector<int> splits;
  while (cur != 0) {
    cur = pr[cur][k];
    k--;
    if (cur != 0) {
      splits.push_back(cur);
    }
  }
  reverse(splits.begin(), splits.end());
  for (int split : splits) {
    cout << split << " ";
  }
  cout << '\n';
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:79:69: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type&, long long int)'
   79 |         dp[i][j] = min(dp[i][j], dp[prev - 1][j - 1] + cost(prev, i));
      |                                                                     ^
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:6:
/usr/include/c++/10/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++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
sequence.cpp:79:69: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   79 |         dp[i][j] = min(dp[i][j], dp[prev - 1][j - 1] + cost(prev, i));
      |                                                                     ^
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:6:
/usr/include/c++/10/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++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
sequence.cpp:79:69: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   79 |         dp[i][j] = min(dp[i][j], dp[prev - 1][j - 1] + cost(prev, i));
      |                                                                     ^
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:6:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
sequence.cpp:79:69: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   79 |         dp[i][j] = min(dp[i][j], dp[prev - 1][j - 1] + cost(prev, i));
      |                                                                     ^
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:6:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
sequence.cpp:79:69: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   79 |         dp[i][j] = min(dp[i][j], dp[prev - 1][j - 1] + cost(prev, i));
      |                                                                     ^