Submission #676177

# Submission time Handle Problem Language Result Execution time Memory
676177 2022-12-29T16:26:36 Z armashka Cigle (COI21_cigle) C++17
48 / 100
1000 ms 13240 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int a[5001], pref[5001], dp[5001][5001];
bool visited[5001][5001];

void compute(int l, int r) {
    if (visited[l][r]) return;
    visited[l][r] = true;

    int cnt = 0, curr_sm = 0;
    for (int i = l - 1, j = l; i; i--) {
        while (pref[l - 1] - pref[i - 1] > curr_sm && j <= r)
            curr_sm += a[j++];
        compute(i, l - 1);
        dp[l][r] = max(dp[l][r], dp[i][l - 1] + cnt);
        if (pref[l - 1] - pref[i - 1] == curr_sm && j <= r) cnt++;
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        pref[i] = a[i] + pref[i - 1];
    }

    for (int i = 1; i <= n; i++) visited[1][i] = true;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        compute(i, n);
        ans = max(ans, dp[i][n]);
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 2 ms 980 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 2 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 4876 KB Output is correct
2 Correct 91 ms 4884 KB Output is correct
3 Correct 93 ms 4840 KB Output is correct
4 Correct 101 ms 4856 KB Output is correct
5 Correct 92 ms 4896 KB Output is correct
6 Correct 104 ms 4876 KB Output is correct
7 Correct 104 ms 4948 KB Output is correct
8 Correct 113 ms 4884 KB Output is correct
9 Correct 105 ms 4860 KB Output is correct
10 Correct 97 ms 5028 KB Output is correct
11 Correct 98 ms 4856 KB Output is correct
12 Correct 95 ms 4904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 2 ms 980 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 2 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
21 Correct 88 ms 4876 KB Output is correct
22 Correct 91 ms 4884 KB Output is correct
23 Correct 93 ms 4840 KB Output is correct
24 Correct 101 ms 4856 KB Output is correct
25 Correct 92 ms 4896 KB Output is correct
26 Correct 104 ms 4876 KB Output is correct
27 Correct 104 ms 4948 KB Output is correct
28 Correct 113 ms 4884 KB Output is correct
29 Correct 105 ms 4860 KB Output is correct
30 Correct 97 ms 5028 KB Output is correct
31 Correct 98 ms 4856 KB Output is correct
32 Correct 95 ms 4904 KB Output is correct
33 Correct 96 ms 4908 KB Output is correct
34 Correct 88 ms 4884 KB Output is correct
35 Correct 91 ms 4852 KB Output is correct
36 Correct 89 ms 4840 KB Output is correct
37 Correct 104 ms 4944 KB Output is correct
38 Correct 116 ms 4900 KB Output is correct
39 Correct 126 ms 4884 KB Output is correct
40 Correct 138 ms 4896 KB Output is correct
41 Correct 135 ms 4888 KB Output is correct
42 Correct 112 ms 4992 KB Output is correct
43 Correct 101 ms 4916 KB Output is correct
44 Correct 126 ms 4988 KB Output is correct
45 Correct 107 ms 4944 KB Output is correct
46 Correct 118 ms 4884 KB Output is correct
47 Correct 119 ms 4892 KB Output is correct
48 Correct 103 ms 4868 KB Output is correct
49 Correct 101 ms 4896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 2 ms 980 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 2 ms 980 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
21 Correct 88 ms 4876 KB Output is correct
22 Correct 91 ms 4884 KB Output is correct
23 Correct 93 ms 4840 KB Output is correct
24 Correct 101 ms 4856 KB Output is correct
25 Correct 92 ms 4896 KB Output is correct
26 Correct 104 ms 4876 KB Output is correct
27 Correct 104 ms 4948 KB Output is correct
28 Correct 113 ms 4884 KB Output is correct
29 Correct 105 ms 4860 KB Output is correct
30 Correct 97 ms 5028 KB Output is correct
31 Correct 98 ms 4856 KB Output is correct
32 Correct 95 ms 4904 KB Output is correct
33 Correct 96 ms 4908 KB Output is correct
34 Correct 88 ms 4884 KB Output is correct
35 Correct 91 ms 4852 KB Output is correct
36 Correct 89 ms 4840 KB Output is correct
37 Correct 104 ms 4944 KB Output is correct
38 Correct 116 ms 4900 KB Output is correct
39 Correct 126 ms 4884 KB Output is correct
40 Correct 138 ms 4896 KB Output is correct
41 Correct 135 ms 4888 KB Output is correct
42 Correct 112 ms 4992 KB Output is correct
43 Correct 101 ms 4916 KB Output is correct
44 Correct 126 ms 4988 KB Output is correct
45 Correct 107 ms 4944 KB Output is correct
46 Correct 118 ms 4884 KB Output is correct
47 Correct 119 ms 4892 KB Output is correct
48 Correct 103 ms 4868 KB Output is correct
49 Correct 101 ms 4896 KB Output is correct
50 Execution timed out 1097 ms 13240 KB Time limit exceeded
51 Halted 0 ms 0 KB -