# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
135201 | 2019-07-23T19:44:26 Z | pedro_sponchiado | Split the sequence (APIO14_sequence) | C++17 | 952 ms | 25396 KB |
#include<bits/stdc++.h> using namespace std; const long long int INF=112345678912345678; const int maxn=10010; const int maxk=210; int n, d; int a[maxn]; long long int parc[maxn], parc_2[maxn]; long long int s_2[maxn]; long long int S_2(int i, int j){ return s_2[j]-s_2[i]-parc[i]*(parc[j]-parc[i]); } long long int dp[maxn][maxk]; int opt[maxn][maxk]; int main(){ scanf("%d %d", &n, &d); for(int i=1; i<=n; i++){ scanf("%d", &a[i]); parc[i]=parc[i-1]+a[i]; parc_2[i]=parc_2[i-1]+a[i]*a[i]; s_2[i]=(parc[i]*parc[i]-parc_2[i])/2; } for(int i=1; i<=n; i++) dp[i][0]=s_2[i]; for(int k=1; k<=d; k++){ for(int i=1; i<=n; i++){ dp[i][k]=INF; if(k>=i)continue; for(int l=1; l<i; l++){ if(dp[i][k]>dp[l][k-1]+S_2(l+1, i)){ dp[i][k]=dp[l][k-1]+S_2(l+1, i); opt[i][k]=l; } } // printf("dp[%d][%d]=%lld\n", i, k, dp[i][k]); } } printf("%lld\n", s_2[n]-dp[n][d]); int at=n; vector<int> aux; for(int i=d; i>=1; i--){ aux.push_back(opt[at][i]); at=opt[at][i]; } for(int i=d-1; i>=0; i--) printf("%d ", aux[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | declared answer doesn't correspond to the split scheme: declared = 117, real = 99 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 504 KB | declared answer doesn't correspond to the split scheme: declared = 1094317, real = 1064057 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 888 KB | declared answer doesn't correspond to the split scheme: declared = 614151844, real = 414151152 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 2808 KB | declared answer doesn't correspond to the split scheme: declared = 21510046, real = 21484686 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 952 ms | 25396 KB | declared answer doesn't correspond to the split scheme: declared = 2018738064, real = 1818678300 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 632 KB | declared answer doesn't correspond to the split scheme: declared = 96, real = 2757000 |
2 | Halted | 0 ms | 0 KB | - |