Submission #967512

# Submission time Handle Problem Language Result Execution time Memory
967512 2024-04-22T09:48:07 Z Halym2007 Split the sequence (APIO14_sequence) C++17
0 / 100
56 ms 131072 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz size()
const int N = 1e5 + 5;
ll a[N], dp[N][205], par[N][205], p[N];
int n, k;
 
int main () {
//	freopen ("sequence.in", "r", stdin);
//	freopen ("sequence.out", "w", stdout);
//	freopen ("input.txt", "r", stdin);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
//	reverse (a + 1,a + n + 1);
//	for (int i = 1; i <= n; ++i) {
//		p[i] = p[i - 1] + a[i];
//	}
	// dp[i][j] i-cenli j grupba bolemde maximum value.
	p[n] = a[n];
	for (int i = n - 1; i > 0; i--) {
		p[i] = p[i + 1] + a[i];
		for (int x = 2; x <= min (n - i + 1, k + 1); ++x) {
			for (int j = i + 1; j <= min (n, i + x - 1); ++j) {
				ll val = dp[j][x - 1] + p[j] * (p[i] - p[j]);
				if (val >= dp[i][x]) {
//					if (i == 2 and x == 2) {
//						cout << "ll : " << j << " " << val << " " << p[j] << " " << (p[i] - p[j]) << "\n";
//					}
					dp[i][x] = val;
					par[i][x] = j;
				}
			}
		}
	}
//	cout << dp[1][3];
//	return 0;
	vector <int> cyk;
	int y = k + 1, x = 1;
	while (1) {
		x = par[x][y];
		if (!x) break;
		cyk.pb (x);
		y--;
	}
	cout << dp[1][k + 1] << "\n";
//	assert ((int)cyk.sz == k);
	for (int i : cyk) {
		cout << i << " ";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB declared answer doesn't correspond to the split scheme: declared = 108, real = 95
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB declared answer doesn't correspond to the split scheme: declared = 131300, real = 161567
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4700 KB declared answer doesn't correspond to the split scheme: declared = 484137, real = 484127
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8028 KB declared answer doesn't correspond to the split scheme: declared = 228040, real = 263987
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 37148 KB declared answer doesn't correspond to the split scheme: declared = 908376, real = 978237
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 56 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -