# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92399 | Vardanyan | Split the sequence (APIO14_sequence) | C++14 | 2073 ms | 4616 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize "-O3"
#include<bits/stdc++.h>
using namespace std;
const int N = 1000*100+5;
const long long INF = 1000000000000000000;
int a[N];
long long pref[N];
pair<long long,int> dp[208][N];
int par[208][N];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
for(int i = 1;i<=n;i++) scanf("%d",&a[i]);
for(int i = 1;i<=n;i++) pref[i] = pref[i-1]+a[i];
// node* old = new node();
// node* nold = new node();
for(int kk = 1;kk<=k;kk++){
for(int i = kk+1;i<=n;i++){
int pos = 0;
while(1){
bool f = false;
for(int j = pos+1;j<i && j<pos+100;j++){
if(dp[kk-1][j].first+(pref[i]-pref[j])*pref[j]>dp[kk][i].first){
dp[kk][i].first = dp[kk-1][j].first+(pref[i]-pref[j])*pref[j];
dp[kk][i].second = j;
pos = j;
f = true;
break;
}
}
if(!f) break;
}
}
}
printf("%lld\n",dp[k][n].first);
int kk = k;
int nn = n;
while(kk>0){
printf("%d\n",dp[kk][nn].second);
nn = dp[kk][nn].second;
kk--;
}
printf("\n");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |