이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define REP(i,n) for (int i = 0; i<n; ++i)
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y){cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif // BALBIT
#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
struct line{
ll m,b;
int id;
};
double its(line a, line b){
if (a.m == b.m) return 1e18+1029;
return (b.b-a.b) / (double)(a.m-b.m);
}
list<line>dq[203];
int dp[100005][203];
int frm[100005][203];
ll ps[100005];
signed main(){
IOS();
int n,K; cin>>n>>K; ++K;
for (int i = 0; i<n; ++i) {
cin>>ps[i+1]; ps[i+1] += ps[i];
}
memset(dp, 0x3f, sizeof dp);
dp[0][0] = 0;
for (int i=1;i<=n;++i){
for (int k=1; k<=K; ++k) {
for (int j = 0; j<i; ++j) {
ll tt = dp[j][k-1] + (ps[i] - ps[j]) * (ps[i] - ps[j]);
if (tt < dp[i][k]) {
frm[i][k] = j; dp[i][k] = tt;
}
}
// bug(i,k,dp[i][k]);
}
}
// bug(dp[n][K]);
cout<<(ps[n]*ps[n] - dp[n][K]) / 2<<endl;
int at = frm[n][K];
for (int k = K-1; at != 0; --k) {
cout<<at<<' ';
at = frm[at][k];
}
}
/*
7 3
4 1 3 4 0 2 3
*/
# | 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... |