이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<ll, ll>
#define f first
#define s second
const int inf = 0x3f3f3f3f;
const int maxn = 1001, maxk = 202;
int n, k;
ll a[maxn];
pi l[maxk][maxn];
int s[maxk], e[maxk];
ll c;
bool cp(pi x, pi y, pi z){
return (x.f - z.f) * (y.s - x.s) >= (x.f - y.f) * (z.s - x.s);
}
ll f(ll x, ll y, ll z){
return l[x][y].f * z + l[x][y].s;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
k++;
l[0][0] = {0, 0};
for(int i = 1; i <= k; i++) l[i][0] = {inf, inf};
for(int i = 1; i <= n; i++){
ll x;
cin >> x;
c += x;
for(int j = k; j; j--){
while(e[j - 1] - s[j - 1] > 1 && f(j - 1, s[j - 1], c) >= f(j - 1, s[j - 1] + 1, c)) s[j - 1]++;
pi p = {-2 * c, 2 * c * c + f(j - 1, s[j - 1], c)};
while(e[j] - s[j] > 2 && cp(l[j][e[j] - 2], l[j][e[j] - 1], p)) e[j]--;
l[j][e[j]++] = p;
}
}
cout << ((2 * c * c - l[k][e[k] - 1].s) / 2) << endl;
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... |