Submission #420500

# Submission time Handle Problem Language Result Execution time Memory
420500 2021-06-08T12:04:31 Z Berted Cigle (COI21_cigle) C++14
100 / 100
490 ms 165256 KB
#include <iostream>

using namespace std;

int N, A[5001];
int cst[5001][5001], DP[5001][5001], pref[5001], suf[5001];

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++)
	{
		int sumL = 0, sumR = 0, l = i - 1, r = i;
		while (l >= 0 && r < N)
		{
			if (sumL + A[l] < sumR + A[r]) {sumL += A[l--];}
			else {sumR += A[r++];}

			if (l >= 0 && r < N && sumL == sumR) {cst[i][l] = 1; cst[i][r] = 1;}
		}
		for (int j = i + 1; j < N; j++) cst[i][j] = cst[i][j - 1] + cst[i][j];
		for (int j = i - 2; j >= 0; j--) cst[i][j] = cst[i][j + 1] + cst[i][j];
	}

	for (int i = 0; i < N; i++)
	{
		if (i)
		{
			for (int j = 0; j < i; j++) 
			{
				pref[j] = DP[j][i - 1];
				if (j) pref[j] = max(pref[j - 1], pref[j]);
			}
			for (int j = i - 1; j >= 0; j--)
			{
				suf[j] = DP[j][i - 1] + cst[i][j];
				if (j + 1 < i - 1) suf[j] = max(suf[j + 1], suf[j]);
			}
		}
		
		int k = i - 1;
		for (int j = i; j < N; j++) 
		{
			while (k >= 0 && cst[i][k] <= cst[i][j]) {k--;}
			if (k + 1 < i) DP[i][j] = suf[k + 1];
			if (k >= 0) DP[i][j] = max(DP[i][j], pref[k] + cst[i][j]);
		}
	}

	/*for (int i = 0; i < N; i++)
	{
		for (int j = i; j < N; j++)
		{
			cerr << DP[i][j] << " ";
		}
		cerr << "\n";
	}*/

	int res = 0;
	for (int i = 0; i < N; i++) {res = max(res, DP[i][N - 1]);}

	cout << res << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 972 KB Output is correct
20 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5708 KB Output is correct
2 Correct 5 ms 5708 KB Output is correct
3 Correct 6 ms 5708 KB Output is correct
4 Correct 5 ms 5752 KB Output is correct
5 Correct 5 ms 5788 KB Output is correct
6 Correct 6 ms 5708 KB Output is correct
7 Correct 6 ms 5708 KB Output is correct
8 Correct 6 ms 5708 KB Output is correct
9 Correct 6 ms 5708 KB Output is correct
10 Correct 6 ms 5808 KB Output is correct
11 Correct 6 ms 5708 KB Output is correct
12 Correct 5 ms 5708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 972 KB Output is correct
20 Correct 1 ms 972 KB Output is correct
21 Correct 7 ms 5708 KB Output is correct
22 Correct 5 ms 5708 KB Output is correct
23 Correct 6 ms 5708 KB Output is correct
24 Correct 5 ms 5752 KB Output is correct
25 Correct 5 ms 5788 KB Output is correct
26 Correct 6 ms 5708 KB Output is correct
27 Correct 6 ms 5708 KB Output is correct
28 Correct 6 ms 5708 KB Output is correct
29 Correct 6 ms 5708 KB Output is correct
30 Correct 6 ms 5808 KB Output is correct
31 Correct 6 ms 5708 KB Output is correct
32 Correct 5 ms 5708 KB Output is correct
33 Correct 5 ms 5708 KB Output is correct
34 Correct 5 ms 5708 KB Output is correct
35 Correct 5 ms 5708 KB Output is correct
36 Correct 6 ms 5708 KB Output is correct
37 Correct 6 ms 5708 KB Output is correct
38 Correct 6 ms 5708 KB Output is correct
39 Correct 7 ms 5748 KB Output is correct
40 Correct 6 ms 5776 KB Output is correct
41 Correct 6 ms 5708 KB Output is correct
42 Correct 6 ms 5708 KB Output is correct
43 Correct 6 ms 5708 KB Output is correct
44 Correct 6 ms 5708 KB Output is correct
45 Correct 6 ms 5812 KB Output is correct
46 Correct 24 ms 5700 KB Output is correct
47 Correct 6 ms 5708 KB Output is correct
48 Correct 6 ms 5708 KB Output is correct
49 Correct 6 ms 5708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 972 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 1 ms 972 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 972 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 972 KB Output is correct
20 Correct 1 ms 972 KB Output is correct
21 Correct 7 ms 5708 KB Output is correct
22 Correct 5 ms 5708 KB Output is correct
23 Correct 6 ms 5708 KB Output is correct
24 Correct 5 ms 5752 KB Output is correct
25 Correct 5 ms 5788 KB Output is correct
26 Correct 6 ms 5708 KB Output is correct
27 Correct 6 ms 5708 KB Output is correct
28 Correct 6 ms 5708 KB Output is correct
29 Correct 6 ms 5708 KB Output is correct
30 Correct 6 ms 5808 KB Output is correct
31 Correct 6 ms 5708 KB Output is correct
32 Correct 5 ms 5708 KB Output is correct
33 Correct 5 ms 5708 KB Output is correct
34 Correct 5 ms 5708 KB Output is correct
35 Correct 5 ms 5708 KB Output is correct
36 Correct 6 ms 5708 KB Output is correct
37 Correct 6 ms 5708 KB Output is correct
38 Correct 6 ms 5708 KB Output is correct
39 Correct 7 ms 5748 KB Output is correct
40 Correct 6 ms 5776 KB Output is correct
41 Correct 6 ms 5708 KB Output is correct
42 Correct 6 ms 5708 KB Output is correct
43 Correct 6 ms 5708 KB Output is correct
44 Correct 6 ms 5708 KB Output is correct
45 Correct 6 ms 5812 KB Output is correct
46 Correct 24 ms 5700 KB Output is correct
47 Correct 6 ms 5708 KB Output is correct
48 Correct 6 ms 5708 KB Output is correct
49 Correct 6 ms 5708 KB Output is correct
50 Correct 376 ms 165048 KB Output is correct
51 Correct 376 ms 165068 KB Output is correct
52 Correct 387 ms 165148 KB Output is correct
53 Correct 369 ms 165100 KB Output is correct
54 Correct 391 ms 165176 KB Output is correct
55 Correct 381 ms 165060 KB Output is correct
56 Correct 436 ms 165256 KB Output is correct
57 Correct 449 ms 165156 KB Output is correct
58 Correct 459 ms 165132 KB Output is correct
59 Correct 431 ms 165104 KB Output is correct
60 Correct 448 ms 165096 KB Output is correct
61 Correct 460 ms 165096 KB Output is correct
62 Correct 428 ms 165128 KB Output is correct
63 Correct 391 ms 165076 KB Output is correct
64 Correct 414 ms 165088 KB Output is correct
65 Correct 423 ms 165104 KB Output is correct
66 Correct 424 ms 165064 KB Output is correct
67 Correct 394 ms 165144 KB Output is correct
68 Correct 377 ms 165084 KB Output is correct
69 Correct 384 ms 165060 KB Output is correct
70 Correct 414 ms 165100 KB Output is correct
71 Correct 490 ms 165148 KB Output is correct
72 Correct 425 ms 165056 KB Output is correct