Submission #959892

# Submission time Handle Problem Language Result Execution time Memory
959892 2024-04-09T09:35:30 Z mannshah1211 Split the sequence (APIO14_sequence) C++17
0 / 100
39 ms 13656 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 ((int64_t) (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));
  auto compute = [&](auto&& self, int at, int l, int r, int bl, int br) -> void {
    if (l > r) {
      return;
    }
    int m = (l + r) / 2;
    pair<int64_t, int> best = make_pair(INT64_MAX, -1);
    for (int i = bl; i <= min(m, br); i++) {
      best = min(best, make_pair(dp[i - 1][at - 1] + cost(i, m), i));
    }
    pr[m][at] = best.second;
    dp[m][at] = best.first;
    self(self, at, l, m - 1, bl, pr[m][at]);
    self(self, at, m + 1, r, pr[m][at], br);
  };
  for (int i = 1; i <= k; i++) {
    compute(compute, i, 1, n, 1, n);
  }
  cout << ((int64_t) 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';
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Integer 50 violates the range [1, 49]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB declared answer doesn't correspond to the split scheme: declared = 610590000, real = 507121050
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB declared answer doesn't correspond to the split scheme: declared = 21503404, real = 14766072
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1624 KB declared answer doesn't correspond to the split scheme: declared = 1818678304, real = 1396709524
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 13656 KB declared answer doesn't correspond to the split scheme: declared = 19795776960, real = 16496882861
2 Halted 0 ms 0 KB -