Submission #750482

# Submission time Handle Problem Language Result Execution time Memory
750482 2023-05-29T14:47:49 Z Sarpa Split the sequence (APIO14_sequence) C++14
0 / 100
54 ms 84768 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 1 ms 340 KB contestant found the optimal answer: 108 == 108
2 Correct 1 ms 340 KB contestant found the optimal answer: 999 == 999
3 Correct 0 ms 340 KB contestant found the optimal answer: 0 == 0
4 Incorrect 1 ms 340 KB declared answer doesn't correspond to the split scheme: declared = 1542525, real = 1542524
5 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 1 ms 468 KB contestant found the optimal answer: 610590000 == 610590000
2 Incorrect 0 ms 468 KB declared answer doesn't correspond to the split scheme: declared = 311836831, real = 307850391
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 = 22047490, real = 21436600
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8788 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Incorrect 6 ms 8788 KB declared answer doesn't correspond to the split scheme: declared = 1551680352, real = 1100458579
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 84768 KB declared answer doesn't correspond to the split scheme: declared = 24949314369, real = 18169520649
2 Halted 0 ms 0 KB -