Submission #990883

# Submission time Handle Problem Language Result Execution time Memory
990883 2024-05-31T17:21:23 Z ToniB Bigger segments (IZhO19_segments) C++17
13 / 100
25 ms 13148 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 3005;
typedef long long ll;

int n, a[N], dp[N][N];
ll pre[N];

ll sum(int i, int j) {
	if (i) return pre[j] - pre[i - 1];
	return pre[j];
}

int main(){
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	
	pre[0] = a[0];
	for (int i = 1; i < n; ++i) pre[i] = a[i] + pre[i - 1];
	
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) dp[i][j] = -1e9;
	}
	
	for (int i = 0; i < n; ++i) {
		dp[0][i] = 1;
	}
	
	for (int i = 1; i < n; ++i) {
		for (int j = i; j < n; ++j) {
			for (int k = 0; k < i; ++k) {
				if (sum(i, j) >= sum(k, i - 1)) dp[i][j] = max(dp[i][j], dp[k][i - 1] + 1);
			}
		}
	}
	
	int ans = 0;
	for (int i = 0; i < n; ++i) ans = max(ans, dp[i][n - 1]);
	
	int gr = 0;
	ll sum = 0, cur = 0;
	for (int i = 0; i < n; ++i) {
		cur += a[i];
		if (cur >= sum) {
			sum = cur;
			++gr;
			cur = 0LL;
		}
	}

	assert(gr == ans || gr + 1 == ans);

	cout << ans << "\n";
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2536 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2536 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 21 ms 6488 KB Output is correct
17 Runtime error 25 ms 13148 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2536 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 21 ms 6488 KB Output is correct
17 Runtime error 25 ms 13148 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2536 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 21 ms 6488 KB Output is correct
17 Runtime error 25 ms 13148 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2536 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 21 ms 6488 KB Output is correct
17 Runtime error 25 ms 13148 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -