Submission #586086

# Submission time Handle Problem Language Result Execution time Memory
586086 2022-06-29T20:21:07 Z MilosMilutinovic Cigle (COI21_cigle) C++14
100 / 100
240 ms 98512 KB
/**
 *    author:  wxhtzdy
 *    created: 29.06.2022 21:43:16
**/
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[0] = 0;
  vector<long long> pref(n + 1);
  for (int i = 0; i < n; i++) {
    pref[i + 1] = pref[i] + a[i];
  }
  vector<vector<int>> dp(n + 1, vector<int>(n + 1));
  for (int l = 1; l <= n; l++) {
    int ptr = l - 1;
    long long t = pref[ptr] - pref[ptr - 1];
    auto Find = [&](long long x) {
      while (ptr > 1 && x > t) {
        ptr -= 1; 
        t += pref[ptr] - pref[ptr - 1];
      }
      return (x == t ? ptr : 0);
    }; 
    vector<int> pref_mx(n + 1);
    for (int i = 0; i < l; i++) {
      pref_mx[i + 1] = max(pref_mx[i], dp[i][l - 1]);
    }
    int ft = 0;
    for (int r = l; r <= n; r++) {
      dp[l][r] = dp[l][r - 1];
      if (l < r) {
        long long s = pref[r - 1] - pref[l - 1];
        int at = Find(s); 
        if (at >= 1) { 
          ft += 1;
          dp[l][r] = max(dp[l][r], ft + pref_mx[at]);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, dp[i][n]);
  }              
  cout << ans << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 2 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 3 ms 1236 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 2 ms 1236 KB Output is correct
24 Correct 2 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 3 ms 1236 KB Output is correct
27 Correct 2 ms 1236 KB Output is correct
28 Correct 2 ms 1236 KB Output is correct
29 Correct 2 ms 1236 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
31 Correct 2 ms 1236 KB Output is correct
32 Correct 2 ms 1236 KB Output is correct
33 Correct 2 ms 1236 KB Output is correct
34 Correct 1 ms 1236 KB Output is correct
35 Correct 1 ms 1236 KB Output is correct
36 Correct 1 ms 1236 KB Output is correct
37 Correct 2 ms 1236 KB Output is correct
38 Correct 3 ms 1236 KB Output is correct
39 Correct 2 ms 1236 KB Output is correct
40 Correct 2 ms 1236 KB Output is correct
41 Correct 2 ms 1236 KB Output is correct
42 Correct 2 ms 1236 KB Output is correct
43 Correct 2 ms 1236 KB Output is correct
44 Correct 2 ms 1204 KB Output is correct
45 Correct 2 ms 1236 KB Output is correct
46 Correct 2 ms 1236 KB Output is correct
47 Correct 2 ms 1236 KB Output is correct
48 Correct 2 ms 1236 KB Output is correct
49 Correct 2 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 2 ms 1236 KB Output is correct
24 Correct 2 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 3 ms 1236 KB Output is correct
27 Correct 2 ms 1236 KB Output is correct
28 Correct 2 ms 1236 KB Output is correct
29 Correct 2 ms 1236 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
31 Correct 2 ms 1236 KB Output is correct
32 Correct 2 ms 1236 KB Output is correct
33 Correct 2 ms 1236 KB Output is correct
34 Correct 1 ms 1236 KB Output is correct
35 Correct 1 ms 1236 KB Output is correct
36 Correct 1 ms 1236 KB Output is correct
37 Correct 2 ms 1236 KB Output is correct
38 Correct 3 ms 1236 KB Output is correct
39 Correct 2 ms 1236 KB Output is correct
40 Correct 2 ms 1236 KB Output is correct
41 Correct 2 ms 1236 KB Output is correct
42 Correct 2 ms 1236 KB Output is correct
43 Correct 2 ms 1236 KB Output is correct
44 Correct 2 ms 1204 KB Output is correct
45 Correct 2 ms 1236 KB Output is correct
46 Correct 2 ms 1236 KB Output is correct
47 Correct 2 ms 1236 KB Output is correct
48 Correct 2 ms 1236 KB Output is correct
49 Correct 2 ms 1236 KB Output is correct
50 Correct 195 ms 98440 KB Output is correct
51 Correct 187 ms 98440 KB Output is correct
52 Correct 191 ms 98384 KB Output is correct
53 Correct 187 ms 98452 KB Output is correct
54 Correct 193 ms 98448 KB Output is correct
55 Correct 182 ms 98420 KB Output is correct
56 Correct 225 ms 98336 KB Output is correct
57 Correct 215 ms 98448 KB Output is correct
58 Correct 240 ms 98452 KB Output is correct
59 Correct 240 ms 98452 KB Output is correct
60 Correct 217 ms 98468 KB Output is correct
61 Correct 208 ms 98424 KB Output is correct
62 Correct 198 ms 98464 KB Output is correct
63 Correct 192 ms 98460 KB Output is correct
64 Correct 200 ms 98356 KB Output is correct
65 Correct 205 ms 98456 KB Output is correct
66 Correct 201 ms 98512 KB Output is correct
67 Correct 210 ms 98364 KB Output is correct
68 Correct 184 ms 98404 KB Output is correct
69 Correct 190 ms 98476 KB Output is correct
70 Correct 221 ms 98380 KB Output is correct
71 Correct 215 ms 98456 KB Output is correct
72 Correct 215 ms 98384 KB Output is correct