이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #define _GLIBCXX_DEBUG
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <random>
#include <queue>
#include <bitset>
#define int long long
#define dbl long double
#define pb push_back
#define str string
using namespace std;
const int M = 998244353;
int dp[100009][209];
int par[100009][209];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> A(n + 1);
for (int i = 1; i <= n; i++) cin >> A[i];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
dp[i][j] = -1e18;
}
}
vector<int> pref = A;
for (int i = 1; i <= n; i++) pref[i] += pref[i - 1];
for (int t = 1; t <= k; t++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
if (dp[i][t] < dp[j][t - 1] + pref[j] * (pref[i] - pref[j])) {
par[i][t] = j;
dp[i][t] = dp[j][t - 1] + pref[j] * (pref[i] - pref[j]);
}
}
}
}
cout << dp[n][k] << '\n';
int i = n;
int t = k;
while (t--) {
cout << par[i][t] + 1 << ' ';
i = par[i][t];
}
}
# | 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... |