이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 2e2 + 20;
const int maxk = 2e2 + 20;
int par[maxn][maxk] , sum[maxn];
ll dp[maxn][maxk];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n , k;
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> sum[i] , sum[i] += sum[i - 1];
memset(dp , 63 , sizeof dp);
dp[0][0] = 0;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
{
for(int x = 0; x < i; x++)
dp[i][j] = min(dp[i][j] , (sum[i] - sum[x]) * (sum[i] - sum[x]) + dp[x][j - 1]);
for(int x = 0; x < i; x++)
if((sum[i] - sum[x]) * (sum[i] - sum[x]) + dp[x][j - 1] == dp[i][j])
par[i][j] = x;
}
int A = n;
vector<int> ans;
for(int j = k + 1; j > 1; j--)
{
ans.pb(par[A][j]);
A = par[A][j];
}
reverse(ans.begin() , ans.end());
cout << (1LL * (sum[n] * sum[n]) - dp[n][k + 1]) / 2 << endl;
for(auto x : ans)
cout << x << " ";
cout << endl;
}
| # | 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... |