Submission #958126

# Submission time Handle Problem Language Result Execution time Memory
958126 2024-04-05T01:46:32 Z MinaRagy06 Split the sequence (APIO14_sequence) C++17
0 / 100
28 ms 9052 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
const int N = 100'005;
const ll inf = 1e18;
int a[N];
ll prf[N];
int prv[205][N];
array<ll, 2> dp[2][N];
void solve(int j, int l, int r, int optl, int optr) {
	if (l > r) return;
	int i = (l + r) >> 1;
	dp[j][i] = {-inf, -1};
	for (int k = optl; k <= min(i - 1, optr); k++) {
		dp[j][i] = max(dp[j][i], {dp[j - 1][k][0] + prf[k] * (prf[i] - prf[k]), k});
	}
	solve(j, l, i - 1, optl, dp[j][i][1]);
	solve(j, i + 1, r, dp[j][i][1], optr);
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		prf[i] = prf[i - 1] + a[i];
	}
	m++;
	for (int i = 1; i <= n; i++) dp[0][i] = {-inf, -1};
	for (int j = 1; j <= m; j++) {
		dp[j & 1][0] = {-inf, -1};
		solve(j & 1, 1, n, 0, n - 1);
		for (int i = 1; i <= n; i++) {
			prv[j][i] = dp[j & 1][i][1];
		}
	}
	cout << dp[m & 1][n][0] << '\n';
	int j = m, i = n;
	vector<int> ans;
	while (j > 1) {
		ans.push_back(prv[j][i]);
		i = prv[j][i];
		j--;
	}
	reverse(ans.begin(), ans.end());
	for (auto x : ans) {
		cout << x << ' ';
	}
	cout << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8540 KB Integer 0 violates the range [1, 6]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8540 KB declared answer doesn't correspond to the split scheme: declared = 8954153627512919713, real = 694130
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8540 KB declared answer doesn't correspond to the split scheme: declared = 9046967490812027816, real = 5953787
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 8540 KB declared answer doesn't correspond to the split scheme: declared = 9046967490807751710, real = 1677185
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 8792 KB declared answer doesn't correspond to the split scheme: declared = 9215835216617094246, real = 1001287512
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 9052 KB declared answer doesn't correspond to the split scheme: declared = 140737438412171, real = 6201733019
2 Halted 0 ms 0 KB -