Submission #1002834

# Submission time Handle Problem Language Result Execution time Memory
1002834 2024-06-19T20:24:10 Z mariaclara Cigle (COI21_cigle) C++17
100 / 100
195 ms 134596 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e5+5;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define fr first
#define sc second

int n, v[5005], dp[5005][5005], max_dp[5005][5005], pref[5005]; // max_dp[i][j] =  max{dp[1][j], dp[2][j], ..., dp[i][j]}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;

    for(int i = 1; i <= n; i++)
        cin >> v[i], pref[i] = pref[i-1] + v[i];

    // l ... r
    // l-1 ... k
    
    for(int l = 1; l <= n; l++) {
        dp[l][l] = max_dp[l-1][l-1];

        int cnt = 0;
        for(int r = l, k = l-1; r <= n; r++) {
            if(r > l) dp[l][r] = dp[l][r-1];
            if(k >= 1) dp[l][r] = max(dp[l][r], max_dp[k][l-1] + cnt);

            while(k >= 1 and pref[l-1] - pref[k-1] < pref[r] - pref[l-1]) k--;
            if(k >= 1 and pref[l-1] - pref[k-1] == pref[r] - pref[l-1]) cnt++, k--;
        }

        for(int k = 1; k <= l; k++)
            max_dp[k][l] = max(dp[k][l], max_dp[k-1][l]);
    }

    cout << max_dp[n][n] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 984 KB Output is correct
12 Correct 0 ms 1116 KB Output is correct
13 Correct 0 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 0 ms 1116 KB Output is correct
16 Correct 0 ms 1116 KB Output is correct
17 Correct 0 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 0 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5468 KB Output is correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5468 KB Output is correct
4 Correct 2 ms 5332 KB Output is correct
5 Correct 2 ms 5316 KB Output is correct
6 Correct 2 ms 5464 KB Output is correct
7 Correct 3 ms 5464 KB Output is correct
8 Correct 4 ms 5468 KB Output is correct
9 Correct 4 ms 5468 KB Output is correct
10 Correct 2 ms 5468 KB Output is correct
11 Correct 2 ms 5468 KB Output is correct
12 Correct 2 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 984 KB Output is correct
12 Correct 0 ms 1116 KB Output is correct
13 Correct 0 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 0 ms 1116 KB Output is correct
16 Correct 0 ms 1116 KB Output is correct
17 Correct 0 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 0 ms 1116 KB Output is correct
21 Correct 2 ms 5468 KB Output is correct
22 Correct 2 ms 5468 KB Output is correct
23 Correct 2 ms 5468 KB Output is correct
24 Correct 2 ms 5332 KB Output is correct
25 Correct 2 ms 5316 KB Output is correct
26 Correct 2 ms 5464 KB Output is correct
27 Correct 3 ms 5464 KB Output is correct
28 Correct 4 ms 5468 KB Output is correct
29 Correct 4 ms 5468 KB Output is correct
30 Correct 2 ms 5468 KB Output is correct
31 Correct 2 ms 5468 KB Output is correct
32 Correct 2 ms 5468 KB Output is correct
33 Correct 2 ms 5484 KB Output is correct
34 Correct 2 ms 5468 KB Output is correct
35 Correct 2 ms 5468 KB Output is correct
36 Correct 2 ms 5468 KB Output is correct
37 Correct 3 ms 5468 KB Output is correct
38 Correct 3 ms 5464 KB Output is correct
39 Correct 3 ms 5468 KB Output is correct
40 Correct 3 ms 5328 KB Output is correct
41 Correct 4 ms 5468 KB Output is correct
42 Correct 3 ms 5468 KB Output is correct
43 Correct 2 ms 5468 KB Output is correct
44 Correct 3 ms 5468 KB Output is correct
45 Correct 3 ms 5264 KB Output is correct
46 Correct 3 ms 5464 KB Output is correct
47 Correct 3 ms 5392 KB Output is correct
48 Correct 3 ms 5464 KB Output is correct
49 Correct 2 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 984 KB Output is correct
12 Correct 0 ms 1116 KB Output is correct
13 Correct 0 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 0 ms 1116 KB Output is correct
16 Correct 0 ms 1116 KB Output is correct
17 Correct 0 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 0 ms 1116 KB Output is correct
21 Correct 2 ms 5468 KB Output is correct
22 Correct 2 ms 5468 KB Output is correct
23 Correct 2 ms 5468 KB Output is correct
24 Correct 2 ms 5332 KB Output is correct
25 Correct 2 ms 5316 KB Output is correct
26 Correct 2 ms 5464 KB Output is correct
27 Correct 3 ms 5464 KB Output is correct
28 Correct 4 ms 5468 KB Output is correct
29 Correct 4 ms 5468 KB Output is correct
30 Correct 2 ms 5468 KB Output is correct
31 Correct 2 ms 5468 KB Output is correct
32 Correct 2 ms 5468 KB Output is correct
33 Correct 2 ms 5484 KB Output is correct
34 Correct 2 ms 5468 KB Output is correct
35 Correct 2 ms 5468 KB Output is correct
36 Correct 2 ms 5468 KB Output is correct
37 Correct 3 ms 5468 KB Output is correct
38 Correct 3 ms 5464 KB Output is correct
39 Correct 3 ms 5468 KB Output is correct
40 Correct 3 ms 5328 KB Output is correct
41 Correct 4 ms 5468 KB Output is correct
42 Correct 3 ms 5468 KB Output is correct
43 Correct 2 ms 5468 KB Output is correct
44 Correct 3 ms 5468 KB Output is correct
45 Correct 3 ms 5264 KB Output is correct
46 Correct 3 ms 5464 KB Output is correct
47 Correct 3 ms 5392 KB Output is correct
48 Correct 3 ms 5464 KB Output is correct
49 Correct 2 ms 5468 KB Output is correct
50 Correct 153 ms 134228 KB Output is correct
51 Correct 149 ms 134224 KB Output is correct
52 Correct 166 ms 134224 KB Output is correct
53 Correct 163 ms 134436 KB Output is correct
54 Correct 191 ms 134372 KB Output is correct
55 Correct 155 ms 134224 KB Output is correct
56 Correct 176 ms 134324 KB Output is correct
57 Correct 174 ms 134224 KB Output is correct
58 Correct 192 ms 134340 KB Output is correct
59 Correct 187 ms 134224 KB Output is correct
60 Correct 182 ms 134228 KB Output is correct
61 Correct 169 ms 134228 KB Output is correct
62 Correct 153 ms 134228 KB Output is correct
63 Correct 153 ms 134228 KB Output is correct
64 Correct 155 ms 134224 KB Output is correct
65 Correct 172 ms 134448 KB Output is correct
66 Correct 195 ms 134416 KB Output is correct
67 Correct 154 ms 134228 KB Output is correct
68 Correct 162 ms 134260 KB Output is correct
69 Correct 147 ms 134224 KB Output is correct
70 Correct 175 ms 134224 KB Output is correct
71 Correct 192 ms 134596 KB Output is correct
72 Correct 177 ms 134220 KB Output is correct