Submission #967474

# Submission time Handle Problem Language Result Execution time Memory
967474 2024-04-22T07:43:01 Z Halym2007 Split the sequence (APIO14_sequence) C++17
0 / 100
2000 ms 4036 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
ll a[N], dp[N][205];
int n, k;
ll sum (int x, int y) {
	ll ret = 0;
	for (int i = x; i <= y; ++i) {
		ret += a[i];
	}
	return ret;
} 


int main () {
//	freopen ("sequence.in", "r", stdin);
//	freopen ("sequence.out", "w", stdout);
//	freopen ("input.txt", "r", stdin);
	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) {
//		for (int j = 1; j <= min (i, k); ++j) {
//			dp[i][j] = 0;
//		}
//	}
	// dp[i][j] i-cenli j grupba bolemde maximum value.
//	dp[1][1] = a[1];
	for (int i = 2; i <= n; ++i) {
		for (int x = 2; x <= min (i, k + 1); ++x) {
			for (int j = x - 1; j < i; ++j) {
				dp[i][x] = max (dp[i][x], dp[j][x - 1] + sum (j + 1, i) * sum (1, j));
//				if (i == 2 and x == 2) {
//					cout << sum (1, j) << " " << sum (j + 1, i) << " ";
//					return 0;
//				}
			}
		}
	}
//	cout << dp[2][2];
//	return 0;
	cout << dp[n][k + 1];
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 600 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 346 ms 1876 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2090 ms 3920 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2025 ms 4036 KB Time limit exceeded
2 Halted 0 ms 0 KB -