이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Suleyman Atayew
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <bitset>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define N 200010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define mod 1000000007
#define pii pair <ll, ll>
#define sz(a) (ll)(a.size())
ll bigmod(ll a, ll b) { if(b==0)return 1; ll ret = bigmod(a, b/2); return ret * ret % mod * (b%2 ? a : 1) % mod; }
using namespace std;
ll n, k;
ll v[N], p[N], dp[N][300], pr[N][300];
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
cin >> n >> k;
for(ll i = 1; i <= n; i++)
cin >> v[i], p[i] = p[i-1] + v[i];
for(ll i = 1; i <= k; i++) {
ll in = i;
for(ll h = i+1; h <= n; h++) {
while(in < h && (p[h] - p[in-1]) * p[in-1] + dp[in-1][i-1] <= (p[h] - p[in]) * p[in] + dp[in][i-1])
in++;
dp[h][i] = (p[h] - p[in-1]) * p[in-1] + dp[in-1][i-1];
pr[h][i] = in;
// cout << (p[h] - p[in-1]) * p[in-1] + dp[in-1][i-1] << " " << (p[h] - p[in]) * p[in] + dp[in][i-1] << "\n";
}
// cout << "\n";
}
cout << dp[n][k] << "\n";
int x = n, y = k;
while(y > 0) {
cout << pr[x][y]-1 << " ";
x = pr[x][y]-1, y--;
}
}
/*
7 6
4 1 3 4 0 2 3
2 1
100 100
*/
# | 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... |