이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
using namespace std;
const long long inf = 1LL << 60;
int n, m, s[100009], p[209][100009]; long long dp[100009], ndp[100009];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> s[i + 1];
s[i + 1] += s[i];
}
fill(dp + 1, dp + n + 1, inf);
for (int i = 0; i <= m; i++) {
for (int j = 0; j <= n; j++) {
ndp[j] = inf;
for (int k = 0; k < j; k++) {
if (ndp[j] > dp[k] - 2LL * s[k] * s[j]) {
ndp[j] = dp[k] - 2LL * s[k] * s[j];
p[i][j] = k;
}
}
if(ndp[j] != inf) ndp[j] += 2LL * s[j] * s[j];
}
copy(ndp, ndp + n + 1, dp);
}
cout << (2LL * s[n] * s[n] - dp[n]) / 2 << '\n';
int pos = n;
for (int i = m; i >= 1; i--) {
pos = p[i][pos];
cout << pos << (i != 1 ? ' ' : '\n');
}
return 0;
}
# | 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... |