Submission #1084992

# Submission time Handle Problem Language Result Execution time Memory
1084992 2024-09-07T09:51:35 Z mingga Split the sequence (APIO14_sequence) C++17
0 / 100
57 ms 131072 KB
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define inf 2e18
#define fast_cin()                  \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)
#define out(file) freopen(file, "w", stdout)
#define in(file) freopen(file, "r", stdin)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
int MOD = 1e9 + 7;
const int N = 1e5;
int n, k, a[N], trace[N][205], ps[N];

vector<int> pre, cur;

void calc(int l, int r, int optl, int optr, int k) {
  if(l > r) return;
  pair<int, int> best = {-inf, 1};
  int mid = (l + r) >> 1;
  for(int i = optl; i <= min(mid-1, optr); i++) {
    best = max(best, {pre[i] + ps[i] * (ps[mid]-ps[i]), i});
  }
  trace[mid][k] = best.se;
  cur[mid] = best.fi;
  calc(l, mid-1, optl, best.se, k);
  calc(mid+1, r, best.se, optr, k);
}

signed main() {
    fast_cin();
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i], ps[i] = ps[i-1] + a[i];
    pre.resize(n+1, 0);
    cur.resize(n+1, 0);
    for(int i = 1; i <= k; i++) {
      calc(i, n, 1, n, i);
      pre = cur;
    }
    cout << cur[n] << ln;
    vector<int> ans;
    int cur = n;
    for(int i = k; i > 0; i--) {
      ans.pb(trace[cur][i]);
      cur = trace[cur][i] - 1;
    }
    reverse(all(ans));
    for(int x : ans) cout << x << ' ';
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB contestant found the optimal answer: 108 == 108
2 Correct 0 ms 348 KB contestant found the optimal answer: 999 == 999
3 Correct 0 ms 348 KB contestant found the optimal answer: 0 == 0
4 Incorrect 0 ms 344 KB declared answer doesn't correspond to the split scheme: declared = 1542524, real = 1541291
5 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 = 1093956, real = 1093952
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB declared answer doesn't correspond to the split scheme: declared = 610590000, real = 512381152
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 1 ms 1884 KB contestant found the optimal answer: 140412195 == 140412195
3 Incorrect 4 ms 1884 KB Integer 0 violates the range [1, 999]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 16732 KB declared answer doesn't correspond to the split scheme: declared = 1818678304, real = 1793673306
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 57 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -