# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
37547 | Talant | 수열 (APIO14_sequence) | C++11 | 2000 ms | 82880 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll inf = (ll)1e9 + 7;
const int N = (int)1e5 + 7;
ll dp[N][2];
ll p[N];
int pr[N][201];
int n;
ll calc (int r,int l) {
return p[l] * (p[r] - p[l]);
}
void compute (int k,int l,int r,int L,int R) {
if (l > r)
return;
int m = (l + r) >> 1;
dp[m][k & 1] = 0;
pr[m][k] = L;
for (int i = L; i <= min(m - 1,R); i ++) {
ll now = dp[i][k & 1 ^ 1] + calc(m,i);
if (now >= dp[m][k & 1]) {
dp[m][k & 1] = now;
pr[m][k] = i;
}
}
compute (k,l,m - 1,L,pr[m][k]);
compute (k,m + 1,r,pr[m][k],R);
}
main () {
int kk;
scanf ("%d%d", &n,&kk);
for (int i = 1; i <= n; i ++) {
scanf ("%lld", p + i);
p[i] += p[i - 1];
}
for (int i = 1; i <= kk; i ++)
compute (i,1,n,1,n - 1);
printf("%lld\n", dp[n][kk & 1]);
while (kk > 0) {
printf("%d ", pr[n][kk]);
n = pr[n][kk];
kk --;
}
}
/**
7 3
4 1 3 4 0 2 3
**/
컴파일 시 표준 에러 (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... |