Submission #750491

# Submission time Handle Problem Language Result Execution time Memory
750491 2023-05-29T14:53:29 Z Sarpa Split the sequence (APIO14_sequence) C++14
0 / 100
50 ms 84844 KB
// Be nam KHODA
#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define int long long

typedef pair<int, int> pii;

const int N = 1e5 + 10, mx = 200 + 10, inf = 2e18;

int n, k;
int a[N], dp[N][2];
int32_t best[N][mx];

void solve(int k, int l = 0, int r = n - 1, int optl = 0, int optr = n - 1){
  int mid = (l + r) / 2;
  if(l > r) return;
  int ans = -1, sum = 0;
  dp[mid][k&1] = inf;
  for(int i = min(optr, mid); i >= max(1ll, optl); i--){
    sum += a[i];
    if(sum * sum + dp[i - 1][(k - 1)&1] <= dp[mid][k&1]){
      dp[mid][k&1] = sum * sum + dp[i - 1][(k - 1)&1];
      ans = i;
    }
  } 
  best[mid][k] = ans;
  solve(k, l, mid - 1, optl, ans);
  solve(k, mid + 1, r, ans, optr);
}

int32_t main(){
  cin.tie(0), ios::sync_with_stdio(0);
  cin >> n >> k;
  ++k;
  for(int i = 0; i < n; i++)
    cin >> a[i];

  int sum = 0;
  for(int i = 0; i < n; i++){
    sum += a[i];
    dp[i][1] = sum * sum;
  } 

  for(int i = 2; i <= k; i++)
    solve(i);

  sum = (sum * sum - dp[n - 1][k&1]) / 2;
  cout << sum << endl;
  int i = n - 1, kk = k;
  vector<int> ans;
  while(kk != 1){
    ans.push_back(best[i][kk]);
    i = best[i][kk] - 1;
    kk--;
  }
  reverse(all(ans));
  for(auto & v: ans)
    cout << v << ' ';
  return 0;   
}




# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB contestant found the optimal answer: 108 == 108
2 Incorrect 0 ms 340 KB declared answer doesn't correspond to the split scheme: declared = 1037, real = 936
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB declared answer doesn't correspond to the split scheme: declared = 1095062, real = 1093820
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB contestant found the optimal answer: 610590000 == 610590000
2 Incorrect 1 ms 468 KB declared answer doesn't correspond to the split scheme: declared = 361836827, real = 207858609
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1108 KB declared answer doesn't correspond to the split scheme: declared = 22049542, real = 21434764
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8788 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Incorrect 5 ms 8788 KB declared answer doesn't correspond to the split scheme: declared = 1701680360, real = 1024513371
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 84844 KB declared answer doesn't correspond to the split scheme: declared = 24949314377, real = 18169520649
2 Halted 0 ms 0 KB -