이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long lint;
int n,k;
lint dp[100005][2],a[100005];
int track[100005][205];
int main(){
int t;
scanf("%d %d",&n,&k);
for (int i=0; i<n; i++) {
scanf("%d",&t);
a[i+1] = a[i] + t;
}
for (int t=1; t<=k; t++) {
for (int i=1; i<=n; i++) {
lint res = -1e9;
for (int j=i+1; j<=n; j++) {
lint piv = dp[j][(t-1)%2] + (a[j-1] - a[i-1])*(a[n] - a[j-1]);
if(res < piv){
res = piv;
track[i][t] = j;
}
}
dp[i][t%2] = res;
}
}
printf("%lld\n",dp[1][k%2]);
// dependant on J = dp[j][t-1] + a[j-1] (a[n] - a[j-1])
// dependant on I = -a[i-1]a[n]
// dependant on IJ = a[i-1] * a[j-1]
// lint piv = dp[j][t-1] + (a[j-1] - a[i-1])*(a[n] - a[j-1]);
int pos1 = 1, pos2 = k;
while (pos2){
printf("%d ",track[pos1][pos2]-1);
pos1 = track[pos1][pos2];
pos2--;
}
}
| # | 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... |